SEC36.hss 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. [Main]
  2. Title=#elif
  3. [Top]
  4. One common case of nested conditionals is used to check for more than two
  5. possible alternatives. For example, you might have
  6. <PRE>#if X == 1
  7. ...
  8. #else /* X != 1 */
  9. #if X == 2
  10. ...
  11. #else /* X != 2 */
  12. ...
  13. #endif /* X != 2 */
  14. #endif /* X != 1 */
  15. </PRE>
  16. Another conditional directive, <CODE>#elif</CODE>, allows this to be
  17. abbreviated as follows:
  18. <PRE>#if X == 1
  19. ...
  20. #elif X == 2
  21. ...
  22. #else /* X != 2 and X != 1 */
  23. ...
  24. #endif /* X != 2 and X != 1 */
  25. </PRE>
  26. <CODE>#elif</CODE> stands for &quot;else if&quot;. Like <CODE>#else</CODE>, it goes in the
  27. middle of a conditional group and subdivides it; it does not require a
  28. matching <CODE>#endif</CODE> of its own. Like <CODE>#if</CODE>, the <CODE>#elif</CODE>
  29. directive includes an expression to be tested. The text following the
  30. <CODE>#elif</CODE> is processed only if the original <CODE>#if</CODE>-condition
  31. failed and the <CODE>#elif</CODE> condition succeeds.
  32. <BR><BR>
  33. More than one <CODE>#elif</CODE> can go in the same conditional group. Then
  34. the text after each <CODE>#elif</CODE> is processed only if the <CODE>#elif</CODE>
  35. condition succeeds after the original <CODE>#if</CODE> and all previous
  36. <CODE>#elif</CODE> directives within it have failed.
  37. <BR><BR>
  38. <CODE>#else</CODE> is allowed after any number of <CODE>#elif</CODE> directives, but
  39. <CODE>#elif</CODE> may not follow <CODE>#else</CODE>.