To follow along and try it yourself, download the CPTX from: WhileLoop and open it in Captivate 2017
A “while” loop can be used to repeat a set of actions a certain number of times, or till a condition is met. It can also be used to repeat some actions infinitely.
Let us use an example to demonstrate While loop in Captivate 2017.
- Create a new slide and insert some objects as below. You may use your own assets or use the Arrow and Circle shapes from the Smart shapes menu.
- Each of the Circle shapes has a custom state added to it as shown below:
You can add states to the circles by selecting the circle, going to the Properties Inspector and adding a new State to it:
Let this new state be named “NewState1”
- Add a button to the slide and set its action to “Execute Advanced Action” and add a Script to execute a While loop.
- Create a new advanced action, and check the “Conditional Action” checkbox. You will see an “If’ in the condition section. Click the dropdown next to it and change it to While.
- The script should have a structure as below. (1==1) condition :
Below is the logic:
While (1 == 1) {
Change State of ‘Active Circle’ to NewState1
Apply Flicker Effect on ‘Active Circle’
Change Last Active State back to Normal
}
What we are essentially doing here is, using a (1 is equal to 1) condition to simulate the loop running infinite number of times. The actions in this loop will keep on getting executed while 1 equals 1, i.e. forever. We do three things on repeat:
- Change the state of the last active circle back to its normal state
- Change the next active circle to its Active state
- Apply an effect on the next active circle to make the transition look good
These three actions will be repeatedly executed every 1 second.
Note: While loop has an inbuilt Delay of 1 second. This means that, all actions executed within the loop are looped with a delay of 1 second, per loop. Adding more Delay statements will be exclusive of the inbuilt 1 second delay.
- Now your slide may look something like this:
- Preview this slide and click the button to see the While loop in action.
A similar example is on the first slide. A while loop is used to loop between the states of the top-right images infinitely. The OnEnter action for that slide contains this While loop.