go to previous page   go to home page   go to next page highlighting

Answer:

A loop control variable is incremented.


Postfix Increment Operator

Frequently the last statement in the body of a counting loop is something like:

count = count + 1;

This is so common that there is a shorter way to do it:

count++ ;

Both statements add one to the value in the variable. Almost always the operator is used with an integer variable (although it does work with floating point.) Here is a previously seen program rewritten with this operator:


// Example of a while loop
public class LoopExample
{
  public static void main (String[] args ) 
  {
    // start count out at one
    int count = 1;   
    
    // loop while count is <= 3      
    while ( count <= 3 )   
    {
      System.out.println( "count is:" + count );
      
      // add one to count
      count++ ;      // previously count = count + 1;   
    }
    System.out.println( "Done with the loop" );
  }
}

The "postfix" part of the name means that the operator is placed after the variable name.


QUESTION 15:

What do you suspect this does: count-- ;


go to previous page   go to home page   go to next page