Loops
PRX allows us to create different kinds of loops. With them, we can either iterate over a number range or over lists.
Usage
DO-Statement
To iterate over a number range, we can use the DO
-statement.
In the above example, we've utilized a DO
-loop to print the numbers 1
to 10
. A DO
-loop accepts three parameters:
Be careful to count up the index variable! Otherwise your program will loop indefinitely.
FOREACH-Statement
To iterate over a list, we can use the FOREACH
-statement.
Here, we've achieved the same thing with a FOREACH
-loop. A FOREACH
-loop generally consists of two parameters.
Flow Control
In order to manipulate the flow of a loop, we can use the BREAK
- and CONTINUE
-statements.
BREAK-Statement
With the BREAK
-statement, we can break outside of a loop prematurely.
CONTINUE-Statement
With the CONTINUE
-statement, we can skip an iteration of a loop.
We can also pass a NUM
-parameter to BREAK
or CONTINUE
to affect multiple levels. This is useful in nested loops.
Following that, we will learn how to modularize our program using includes.
Last updated