Controlling code execution
So far, all of the code sections we have written were executed once in the same order as they were sent to the command line. However, one of the most important themes in programming is the flow control—operations that are used to control the sequences of our code execution. For example, we may want to induce the execution of a certain code section only if a condition is met (these are called conditional statements), or we may wish to execute a code section several times, over and over again (these are called loops). In this section, you will learn about three flow control commands: two to construct conditional statements and one to construct loops.
Conditioning execution with conditional statements
The purpose of conditional statements is to condition the execution of a given code section. For example, the second expression in the following code section is a conditional statement using the if
operator:
> x = 3 > if(x > 2) {print("x is large!...