Choosing the Appropriate Loop

Meeting RoomNow that we have looked at the three types of loop which are available in JavaScript (while do, do while and for) let’s look at a programming example more closely.  Suppose we want to get a sequence of exam marks, one after the other from the keyboard, calculate their average and then display this average.

There are three situations, which might arise:

1. The number of marks to be read in is known by the programmer when the program is written.

2. The number of marks to be read in is not known when the program is written but is known when the program is executed.

3. The number of marks to be read in is not known during writing or execution.

Loop Situation 1