For loop
Suppose we want to print 1-100, we can write the following code:
print 1
print 2
print 3
...
print 100
However, the above code is not only tedious, but would quickly become impossible if we want to print a large number, say 1 billion. This is where the for loop
comes in.
For loop executes some code repeatedly. To solve the problem above, we will:
- Start from number 1
- Print the current number
- If the current number is equal to the end number (such as one billion), stop printing, otherwise , increase the current number by 1 and repeat step 2
Add Node
Right-Click anywhere on canvas, select Flow Control/For
Usage
Connect Body
handle to a Print
node, and use the Index
handle as the input of Print
node. When executed, the Print
node will print the current index, starting from 0.
TIP
Unlike other programming languages, End
is included in the loop
Loop Completion
After the loop is finished, nodes connected to Completed
handle will be executed.
Dynamic Start
and End
The value of the Start
and End
handle would come from other nodes: