For Complex Loops

Strategies that use complex loops, such as repeating an operation while a condition is true, are easier to create and take up less space when done in OptoScript. While loops, repeat loops, and for loops are all available.

  • While loops repeat a process while a test is true (the test comes at the beginning of the process).
  • Repeat loops repeat a process until a test is false (the test comes at the end of the process). This kind of loop is guaranteed to execute at least once.
  • For loops repeat a process for a specified number of times.

Here’s an example of a while loop in standard flowchart commands. Compare it with the way it’s programmed in an OptoScript block.

While loop example

In an upcoming lesson, Control Structures, you'll learn more about each of these control structures.

Summary

Summary

An introduction to while loops, repeat loops, and for loops in OptoScript.