Home Segments Top Top Previous Next

415: Mainline

For example, the following method fragment repeatedly decrements n by 1 until n is 0:

while (n != 0) 
 n = n - 1; 

Replacement of the single embedded statement, n = n - 1;, by an embedded block enables the while statement to do useful computation while counting down n to 0:

while (n != 0) { 
 n = n - 1; 
 ... 
}