<<< Coding while statements | Index | An "Endless" Loop Example >>> |
The following demo code displays the total of all the numbers from 10 down to 1:
int x = 10; int total = 0 while( x > 0 ) { total = total + x; x = x – 1; } System.out.println( "Total = " + total );
<<< Coding while statements | Index | An "Endless" Loop Example >>> |