User Guide > User Guide > Using Content Extraction Language > Language Syntax and Examples > if ( condition ) { statements } else { statements }
Was this helpful?
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: 01/25/2022