10. Counting Down


Answer:

21

Counting Down

Recall the general form of a for:

for ( initialize ; test ; change )
loopBody ;

The change can be any statement. It can, for example, decrease the control variable, as in this example:

int count;

for ( count = 10; count >= 0; count-- )
{
System.out.println( "count is: " + count );
}
System.out.println( "\nDone with the loop.\nCount is now" + count);

The expression count-- decrements count by one.





       


Question 10:

Would the output of this program be any different if the expression count-- were changed to --count?