HTML and CSS Reference
In-Depth Information
The JavaScript program starts here.
The while loop is entered. The loop expression will always evaluate to true, caus-
ing the body of the loop to be entered.
The user is prompted for a grade, which is assigned to the variable grade .
If the variable grade is less than 0 or more than 100, “ Illegal choice ” is printed.
The continue statement sends control back to line 2 and the loop is re-entered,
prompting the user again for a grade.
If a valid grade was entered, and it is greater than 89 and less than 101, the grade
A ” is displayed (see Figure 6.7).
Each else/if branch will be evaluated until one of them is true.
If none of the expressions are true, the else condition is reached and “ You Failed
is displayed.
The user is prompted to see if he or she wants to enter another grade.
10, 11
If the answer is not yes , the break statement takes the user out of the loop, to line
Figure 6.7 The user enters a grade, clicks OK, and gets another alert box.
6.3.6 Nested Loops and Labels
Nested Loops. A loop within a loop is a nested loop. A common use for nested
loops is to display data in rows and columns. One loop handles the rows and the other
handles the columns. The outside loop is initialized and tested, the inside loop then
iterates completely through all of its cycles, and the outside loop starts again where it
left off. The inside loop moves faster than the outside loop. Loops can be nested as
deeply as you wish, but there are times when it is necessary to terminate the loop
owing to some condition.
Search WWH ::

Custom Search