Loops
Last updated
Last updated
The Loop folder in Blockly contains blocks that are used to repeat a block of code multiple times. This can be useful for tasks such as iterating over a list, performing a calculation multiple times, or waiting for a certain amount of time.
To use a loop function, simply connect the block of code that you want to repeat to the loop function. Then, specify the condition for the loop function, or the number of times that you want the loop function to repeat.
This block allows the user to repeat some statements a certain amount of times. You can intuitively choose the number of times and the actions of the robot.
This block has two options: while and until.
If it is set to "while", the robot will repeat the statement set in the "do-gap" while the condition set is true.
If it is set to "until", the robot will repeat the statement set in the "do-gap" while the condition set is false.
This block allows you to customize your own "repeat". In fact, you can choose the variable to use. Take it on the values from the start number to the end number, counting in specified intervals.
When the variable will have the same value as the end value the block will give a false output and will stop the execution, it means that while the condition is verified Misty will keep doing her actions.
Lists in Blockly are ordered collections of items. They can be used to store any type of data, including numbers, strings, and even other lists. We'll explore this element of the programming on the dedicated page.
This block will do a specific action for each term of the list. In the "list-gap" you can insert the name of the list and under, in the "do-gap", the actions.
This block can only be used inside a loop.
You can use the break-out of the containing loop when the user wants to stop the loop early. This can be for a variety of reasons, such as:
You have found what you were looking for.
The loop has reached a certain condition.
Otherwise, you can select "continue with the next iteration". In this case, you will skip the rest of the loop and the program will continue with the next iteration.
This can be for a variety of reasons, such as:
You have already done what you needed to do in the current iteration.
The current iteration does not meet the user criteria.