Handling repetitive tasks with Loop statements
Another valuable concept in programming languages is to iterate through a list or run through a specific set of statements and actions a defined number of times. This can also be achieved in PAD by using loop actions. These are located in the Loops action group.
The Loop action
Let’s start with the Loop
action and create a dice simulator for the Ludo board game. In this board game, players have to circumnavigate the board using pieces of a color chosen before the start of the game. The dice is rolled three times. If the result is a 6, the player can move a piece. If not, they need to try again. Here is the flow to simulate this situation:
Figure 4.11 – Roll the dice flow with a loop statement
The following is a detailed explanation of the steps you see in the previous figure:
- Open the Loops action group and locate the
Loop
action. Drag it onto the workspace and set the following...