Loops

Loops provides blocks that enable you to repeatedly execute a set of instructions, making your programs more efficient and powerful. Instead of manually duplicating code for each iteration, you can use loops to:

  • Process multiple sensor readings

  • Generate patterns for LED displays

  • Handle collections of data

  • Create sequences of operations

repeat

Executes code a specific number of times.

Parameters:

  • Count (Number): How many times to repeat

Example:

Avarage sensor reading

repeat while

Repeats code as long as a condition is true.

Parameters:

  • Condition (Boolean): The condition to check

Example:

Process values while above threshold

repeat until

Repeats code until a condition becomes true.

Parameters:

  • Condition (Boolean): The condition to check

Example:

Read until valid value received

iterator

Returns the current loop iteration number (0-based).

Returns:

  • Iterator (Number): The current loop iteration number

Example:

Alternate on/off pattern for multiple LEDs

Last updated