Do while loop
Do while loop
This function introduces the Maths object and one of its methods, namely the random() method. This generates random numbers in the range 0 - 1. The program will loop so long as the random number is greater than the limit set. In this example 0.1. Once a number less than 0.1 is generated the program is to stop. Again I have no way of telling how many numbers will be printed. If I use a while loop, then if the first number generated is less than the limit I'll never enter the loop.
While loop
While loop
In a previous example a for loop was used to generate a multiplication table. This kind of loop was used because the number of repetitions (or iterations) was known in advance. In the next example the program is going to reverse your name. The program works by starting with last character in your name, writing it down, then writing down the previous character until it reaches the first character. Since I have no way of knowing how long your name is, this would seem to rule out a for loop.
For loop
For loop
We'll use the template window to demonstrate some other features of Javascript. In previous exercises you have written a sequence of Javascript instructions. The next structure to consider is a program loop. I.e. we want the program to repeat a sequence of instructions a number of times. We will use the multiplication tables to demonstrate this. The user will be prompted for a value to be used in the table. You have already met the alert() and confirm() methods, now the prompt() method.
Program flow
Controlling the Flow of Execution?
Fairly often, you need a script to do different things under different conditions. For example, you might write a script that checks the time every hour, and changes some parameter appropriately during the course of the day. You might write a script that can accept some sort of input, and act accordingly. Or you might write a script that repeats a specified action.

