![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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 |