These puzzles provide means for specifying iterations in your Puzzles scenario.
- Infinite Loops Caveat
- Puzzles Reference
Infinite Loops Caveat
Be careful with these puzzles as it is easy to create infinite loops and hang your browser. If you happened to save such a wrongful scenario, you can restore a previous version of your puzzles from backup.
This puzzle runs the puzzles placed in the do slot the specified number of times.
For example, the following set of puzzles creates several copies of the cube and places them randomly on the scene.
for each in list
This puzzle iterates through a specified list and runs the puzzles placed in the do slot for each item in that list. The items for corresponding iteration are accesible via an automatically created variable.
For example, the following set of puzzles adds annotations to all objects from the list.
for each in dict
This puzzle iterates through a specified dictionary and runs the puzzles placed in the do slot for each item in that dictionary. The items for corresponding iteration are accesible via an automatically created key/value variables.
For example, the following set of puzzles prints flight directions stored in the dictionary to the browser console.
This puzzle is similar to for each, except it gives the loop variable values in a numeric sequence.
For example, the following set of puzzles counts from 2 to 10 with the step 2, thus creating numbers 2, 4, 6, 8 and 10, clones the cube on each step, and uses those numbers to position the copies along X axis.
repeat while / until
The repeat while puzzle runs the puzzles placed in the do slot as long as a specified logical condition is true. On the contrary, the repeat until puzzle stops running just after a specified logical condition evaluates to false.
This puzzle is well suited for situations when something is changing inside the loop and this affects your decision to continue or stop performing the iterations. For example, the following set of puzzles, which uses the repeat while variant, keeps asking for the user's answer as long as the user answers "yes".
You can use the repeat until variant to ask the same question but in a slightly more annoying manner, making the answer "no" the only option to stop this.
break / continue
Most loops run until the terminating condition (in the case of repeat puzzles) is met or until all values have been taken by the loop variable (in the case of count with and for each puzzles). This puzzle provide additional means for controlling loop behavior. Although the below examples use the for each puzzle, they can be used with any type of loop.
The break variant provides an early exit. For example, the following set of puzzles performs search for an object named "Cube". Once it is found and the result variable is set, there is no need to iterate any further, and as such we break out of the loop.
On the other hand, the continue variant skips the current iteration so that the next iteration of the loop begins. For example, the following set of puzzles adds annotations to all objects on the scene except "Cube".
Having Troubles with Puzzles?
Seek help on the forums!