[ANSYS, Inc. Logo] return to home search
next up previous contents index

A.11.2 if-else Statement

if-else statements are another type of conditional control statement. The format of an if-else statement is:

if (logical-expression)
  {statements}
else
  {statements}

where logical-expression is the condition to be tested, and the first set of statements are the lines of code that are to be executed if the condition is met. If the condition is not met, then the statements following else are executed.



Example


if (x < 0.)
  y = x/50.;
else
  {
   x = -x;
   y = x/25.;
  }

The equivalent FORTRAN code is shown below for comparison.

       IF (X.LT.0.) THEN
         Y = X/50.
       ELSE
         X = -X
         Y = X/25.
       ENDIF


next up previous contents index Previous: A.11.1 if Statement
Up: A.11 Control Statements
Next: A.11.3 for Loops
Release 12.0 © ANSYS, Inc. 2009-01-14