Loop: Difference between revisions
Updated and revisited the page
-u ndefined- (talk | contribs) m (Use infobox; format consistency)  | 
				 (Updated and revisited the page)  | 
				||
| Line 13: | Line 13: | ||
The Loop block is used to run a script multiple times in the same frame. Often used for processing every element in a [[List Element|list]].  | The Loop block is used to run a script multiple times in the same frame. Often used for processing every element in a [[List Element|list]].  | ||
The loop will execute everything connected to the Do wire Stop - Start times, with the counter incrementing (or decrementing) from Start to Stop on each iteration.  | |||
== Notes ==  | == Notes ==  | ||
* The counter always steps by 1 (or -1, if Start is greater than Stop)  | * The counter always steps by 1 (or -1, if Start is greater than Stop).  | ||
* If a non-integer value is provided for Start, it's rounded down to the next smallest integer.  | * If a non-integer value is provided for Start, it's rounded down to the next smallest integer.  | ||
* If a non-integer value is provided for Stop, it's rounded up to the next biggest integer.  | * If a non-integer value is provided for Stop, it's rounded up to the next biggest integer.  | ||
* The counter includes the Start value, but excludes the Stop value.  | |||
: [[File:Loop example1.png|thumb|none]]  | |||
[[File:  | |||
== Example ==  | == Example ==  | ||
One of the most common uses of loops is to perform some operation to many blocks at once.  | |||
To do that, the blocks should be added to a [[List Element|list]].  | |||
In the example below, we're moving the blocks by (0, 0, 0.1) every frame.  | In the example below, we're moving the blocks by (0, 0, 0.1) every frame.  | ||
{{Image|Loop example2.png}}  | |||
It's mentioned previously that the Counter won't output the Stop value by the end of the loop.  | It's mentioned previously that the Counter won't output the Stop value by the end of the loop.  | ||
It won't be a problem because after we add the last block to a list, it increments the   | It won't be a problem because after we add the last block to a list, it increments the <code>$Length</code> variable by one.  | ||
So, if the last block is assigned to index 4,   | So, if the last block is assigned to index 4, <code>$Length</code> would equal to 5 which is exactly what the Stop input should be to account for every block.  | ||
[[Category:Blocks]]  | [[Category:Blocks]]  | ||