The if Statement
The syntax:
if ( test condition )
{ command(s) }
else
{ command(s) }
- The brackets are require only if there is more than one command.
- The “else” is optional.
- Nesting is allowed.
- Examples: awk_prog8a and awk_prog8b which use awk_data8
Example 1
Example 2
The for Loop
for ( init ; test ; increment )
{ commands }
- init = initialization statement which is executed only once at the start.
- test = A logical expression which is evaluated before execution of the loop body.
- increment = an operation that is performed after each execution of the loop body.
- The brackets are only required if there are multiple commands.
- Example awk_prog9 that uses awk_data9.
Other Loops
while ( condition )
{ commands }
do
{ commands }
while ( condition )