If Statement

The if statement is used to implement a conditional statement. The syntax of the if statement is:

if (expression) statement1 [else statement2]

If expression evaluates to true, statement1 executes. If expression is false, statement2 executes. The expression must evaluate to an integral value; otherwise, the condition is ill-formed. Parentheses around the expression are mandatory.

The else keyword is optional, but no statements can come between if and else.

Nested If statements

Nested if statements require additional attention. A general rule is that the nested conditionals are parsed starting from the innermost conditional, with each else bound to the nearest available if on its left:

if (expression1) statement1
else if (expression2)
  if (expression3) statement2
  else statement3        /* this belongs to: if (expression3) */
else statement4          /* this belongs to: if (expression2) */
  Note : #if and #else preprocessor statements (directives) look similar to if and else statements, but have very different effects. They control which source file lines are compiled and which are ignored.
Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code