The AWK for statement functionally works the same as the AWK while loop; however, the for statement syntax is much easier to use. Its syntax is as follows:
for ( initialization; conditional-expression; increment / decrement )
action statements
The description of different keywords and statement used in for loop syntax above is as follows:
- initialization: Sets the initial value for the counter variable
- conditional-expression: States a condition that is tested at the top of the loop
- increment/decrement: Increment/decrement the counter each time at the bottom of the loop, just before testing the conditional-expression again
For statement starts by performing initialization action, then it checks the conditional-expression ...