Arbortext Command Language > Using the Arbortext Command Language > break and continue
  
break and continue
The break and continue commands are useful in if, while, and for loops. The break command is typically used in combination with a condition. If a break command is executed in a loop, it immediately forces the loop to be broken off.
In the following example, the while loop is broken off when a noname tag occurs to the left of the string Peter. In that case, the while loop is broken off, the replacement does not take place, and the search terminates.
find "Peter"
while ($status == 0) {
if ($tagname == "noname") {
message "noname tag encountered!";
break
}
delete_mark
insert_string "John"
find "Peter"
}
The continue command also breaks off the execution of the loop but does not exit it. It causes the rest of the statements in the current cycle of the loop to be skipped and forces the loop to start at the beginning of the next cycle.
In the following example, the break is replaced by a continue. As in the above example, if the string Peter is preceded by a noname tag, it is not replaced. However, unlike the previous example the loop continues its search. It cycles between continue and while, since that status is still true, thus it is not broken off.
find "Peter"
while ($status == 0)
{
if ($tagname == "noname")
{
message "noname tag encountered!"
continue
}
delete_mark
insert_string "John"
find "Peter"
}
The break command can also be used within a switch statement to transfer control after the end of the switch body. For example:
switch (str) {
case |x|:
if (str == "x1") {
break
}
case |y|:
message "$str starts with y"
break
}