if ( condition ) { statements } else { statements }
The if-else statement provides for decision making in the flow of statements. The else statement is optional. If condition evaluates true, then the if-statements are executed. If condition is false, and there is an else clause, then the else-statements are executed. Statements associated with the if or else clause must appear on the line following the clause. To eliminate any ambiguity, each else is associated with the closest previous unassociated if.
Example 1
if (trim($0(1 11) != "")
inv = rtrim($0(1 11));
# If not blank
# assign characters 1-11 to inv
Example 2
if (cnt < tot)
# If a line remains
accept line[cnt];
# write it
else
# otherwise
tot = 0;
# reinitialize counter
Last modified date: 12/03/2024