Iteration
Loop
The
loop
statement repeats a block of code a specified number of times.
Example
Syntax
number_of_times
: The number of times to repeat the block of commands.commands
: The commands to be executed within the loop.
Example
In this example, the robot will move forward and then turn left three times.
Use Cases
Fibonacci Sequence Generation:
This example demonstrates how the loop
command can be used to repeatedly generate the Fibonacci sequence with a specified number of terms.
Repeated Task Execution:
Here, the loop
command is used to execute a task function multiple times, which can be useful for performing repetitive tasks within a program.
For
Each
Last updated