Page t025, go to NEXT, PREVIOUS, INDEX

More Examples of for Loops


Typically, one sees

      for ( i = 0; i < count; i++ )
      { statement
        . . .
      }

Nested loops might iterate over all pairs with

      for ( i = 0; i < count-1; i++ )
      { for ( j = i+1; j < count; j++ )
        { statement
          . . .
        }
      }

Use of two running indices might be

      for ( i = 0, j = count ; i <= count; i++, j-- )
      { statement
        . . .
      }

C Course, 20-jan-1997, Peter Klok, pfk@hef.kun.nl