AI & Robotics
Chapter-1 : Loops & Functions
UNDERSTANDING LOOPS:
What is a loop?
A loop is a programming concept that allows you to repeat a set of instructions multiple times.
Instead of writing the same code over and over, you can use a loop to do it for you.
Types of loops:
Repeat Loop: Executes the enclosed blocks a specific number of times. For example, ''repeat 5 times” will run the instructions inside the loop five times.
Forever Loop: Continuously executes the enclosed blocks indefinitely until the program is stopped. This is useful for tasks that need to run constantly.
Repeat Until Loop: Executes the enclosed blocks until a certain condition is met. For instance, "repeat until score = 10" will keep running the loop until the score reaches 10.
Why Use Loops?
Efficiency: Loops help in automating repetitive tasks, reducing code redundancy, and enhancing program efficiency.
Simplification: They make complex tasks easier by breaking them into simpler,repeatable steps.
UNDERSTANDING FUNCTIONS:
What is a Function?
A function, also known as a procedure or custom block, ia a reusable sequence of instructions that performs a specific task.
Once defined, you can use it multiple times throughout your program.
Benefits of Using Functions:
Modularity: Breaks down complex problems into manageable parts.
Reusability: Allows the same set of instructions to be used in different parts of the program without rewriting code.
Maintainability: Simplifies updates and debugging, as changes need to be made only in one place.
Readability: Makes the program easier to understand by giving meaningful names to blocks of code.
Example:
In programming, you can create a custom block called “draw square” that contains instructions to draw a square. This block can then be used whenever a square needs to be drawn, without rewriting the drawing instructions each time.
Chapter-2 : AND Logic Gates