The break statement stops processing statements inside of a loop and exits the loop. The break statement is valid only inside of foreach or while loops.
This example is similar to the if statement example except that a break statement has been added. “if else statement” on page 77 provides additional information about the if statement.
The break statement causes the test in the foreach statement to stop once the condition is TRUE rather than continuing to test.
ASL Script (break_do.asl): z = table(); START { rep(IMPORT) } IMPORT { animal:word count:integer eol } do { test="FALSE"; foreach i (z) { if (i == animal) { test="TRUE"; break; } } if (test=="FALSE") { z[animal]=count; } else { z[animal]=z[animal]+count; } } EOF do { foreach i (z) { print(i." count ".z[i]); } } break_do.txt (Input): dog 3 cat 4 canary 3 cat 2 dog 5 dog 1 cat 1 Output: $ sm_adapter --file=break_do.txt break_do.asl dog count 9 cat count 7 canary count 3 $