Page t018, go to NEXT, PREVIOUS, INDEX

if Statement


Example

      if (current_temp > maximum_safe_temp)
      { fprintf ("EMERGENCY: Too hot -- flushing\n");
        flushWithWater ();
      }

Any expression that evaluates to numeric value is allowed

      if ( !(channel = openChannel ("temperature")) )
      { fprintf ("Could not open channel\n");
        exit (1);
      }

Braces are optional when single expression is in the block

      if (x < 0)
        x = -x;    /* abs (x) */
        y = -y;    /* always executed!! */

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