Page t019, go to NEXT, PREVIOUS, INDEX

if else Statement


Example

      if (x < 0)
      { y = -x;
      }
      else
      { y = x;
      }

Condition operator

      y = (x < 0) ? -x : x;    /* y = abs (x) */

Also

      if (x < 0)
      { y = -x;
      }
      else if (x > 0)
      { y = x;
      }
      else
      { y = 0;
      }

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