4.2.6. if-else

Provides a way to specify an alternative statement to execute if the if statement evaluates to False.

Syntax:

if (expression)                  /* If expression is True */
{
    statement_1;                 /* execute statement_1 */
    [statement;]...              /* and these additional statements */
}else                             /* If expression is False */
{
    statement_2;                 /* execute statement_2 */
    [statement;]...              /* and these additional statements */
}

Description

The if-else statement provides a way to specify an alternative statement to execute if the if statement evaluates to False. If the expression evaluates to True, that is nonzero, statement_1 and any following statements are executed, but statement_2 and any following statements are not executed. If the expression evaluates to False, that is zero, statement_2 and any following statements are executed, but statement_1 and any following statements are not executed. If you have more than one statement in the if section or in the else section these must be enclosed in curly braces ({}).

Return Value

None

Rules

None

Example

This example shows how to use if-else in a macro:

if (n==0)
  strcpy(number,"zero");
else
  strcpy(number,"nonzero");

See also

Copyright © 2002-2009 ARM Limited. All rights reserved.ARM DUI 0175K
Non-Confidential