Statements
In the previous section, we learned how to write a very simple script and we saw that a script is just a sequence of commands. In this section, you will learn how to use statements in order to control the behaviour of a script. This enables you to code scripts that can perform different and much more complicated tasks.
Prime numbers
We will discuss the different type of statements: if, for, while
, and so on by evaluating whether a number is a prime number or not. As you know, a prime number (or just a prime) x is a natural positive number that has exactly two divisors—1 and itself. Adivisor y is a natural positive number larger than 1 such that the division x/y has no remainder. From the definition of a prime, we may write a simple program flow chart as shown below. Notice that if 2 is a divisor, then we need not check for any other even number. The algorithm is of course extremely naïve and there are much more efficient ways of evaluating whether a number is a prime number or...