Conditional statements
Conditional statements such as if and switchare used to test expressions and control the flow of execution in AWK programs.All control statements start with special keywords such as ifandswitch todifferentiatethemfrom simple expressions.Within one conditional statementblock,we can have other multiple statementsseparated by braces, newlines, or semicolons. Such conditional statements are known as compound statements.
The if statement
if is a conditional statement used to control the flow of a program.AWK supports three types of if statements:
ifif...elseif...elseif...elseif...
if
This is a single and simple if statement used to test a condition/expression. It executes theactions given in the bodypartonlyif the conditionalexpressionisevaluated as true.Its syntax is as follows:
if ( conditional-expression )
action
- if: The keyword
- conditional-expression: This represents the condition to be tested
- action: An AWK statement for execution
If two or more actions need to be executed when...