Using a loop in a script
A loop is a programming structure where a statement or series of statements is repeated over and over, usually until a condition is satisfied. Two types of loops are available in Interactive layouts: Loop loops and While loops.
A Loop loop (created with the Loop, Break If, and End Loop actions) repeats a series of actions until a particular condition (specified in the Break If action) is satisfied. For example, you can use a Loop loop to keep asking a student a question until he or she gets it right.
A While loop (created with the While and End While actions) repeats a series of actions as long as a particular condition (specified in the While action) is satisfied. For example, you can use a While loop to play an animation until the end user moves the mouse pointer off of the window.
To create a Loop loop or While loop:
- In the Script tab of the Interactive palette, create a script.
- To begin the loop statement, do one of the following things:
- For a Loop loop, add a Loop action (Control > Loop).
- For a While loop, add a While action. To specify the condition that must be met for the loop to continue executing, choose an option from the Object Type drop-down menu; choose the object’s name from the Object drop-down menu; and then choose an option from the Is or the Has drop-down menu. (Note that if you choose Expression from the Object Type drop-down menu, you must enter an expression that evaluates to true or false rather than choosing an option from the Is or the Has drop-down menu.)
- To specify the action to be repeated within the loop, add an action to the script immediately after the If action, and configure it to do what you want. If you want more than one thing to happen in the body of the loop, add additional actions.
- If you are creating a Loop loop, add a Break If action. To specify the condition that must be met for the loop to stop repeating, choose an option from the Object Type drop-down menu; choose the object’s name from the Object drop-down menu; and then choose an option from the Is or the Has drop-down menu.
- To conclude the loop, do one of the following things: