Next: switch Up: if-else Previous: Dangling else

else-if

This is not a new construct but we often meet it, as a multi-way decision:

   if (...)
      statement
   else if (...)
      statement
   else if (...)
      statement
   else if (...)
      statement
   else   /* default: none of the above happened */
      statement

C will evaluate the conditions in turn until it reaches the first true one. It then executes its statement and terminates the chain.



Next: switch Up: if-else Previous: Dangling else


maspjw@
Tue Sep 27 15:29:34 BST 1994