next up previous
Next: Symbolic Constants Up: intro_C_examples Previous: Variables and Arithmetic Expressions

The For Statement

#include <stdio.h>

/* print Fahrenheit-Celsius table */
main()
{
  int fahr;

  for (fahr = 0; fahr <= 300; fahr = fahr + 20)
    printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));
}
$\bullet$
Concepts: Complex expressions in place of simple variables
$\bullet$
Shorthand: fahr = fahr + 20 can be written fahr += 20


Derek C. Richardson 2005-02-03