Flow Control
Pikt scripts run from top to bottom, from beginning to end, unless redirected by one of the flow control constructs. Pikt comes with a panoply of flow control structures, most usual, and a few not so usual. ("The usual" below means that the structure follows the usual C-like or Perl-like behavior.)
STRUCTURE DESCRIPTION if-elif-else-endif the usual (note that you can use elsif and elseif, too; also, fi instead of endif) while-endwhile the usual repeat-until like a do-while loop, except keep looping until the exit condition is true (no do- while, because the "do" keyword is reserved for another use) for-endfor the usual for-in-endfor loop through all the keys in the given associative array foreach-endforeach loop through all the keys in the given associative array break the usual continue the usual (note that you can use cont, too) switch-case-default- the usual breakswitch- (note that you can use breaksw endswitch and endsw, too) again repeat the current rule leave leave the current rule and go on to the next redo reprocess the current input line next go on to the next input line skip n skip ahead n input lines, and resume with the first rule last terminate input processing, go to the end section, if any pause n pause for n seconds quit go on to the next alarm script die "<message>" abort the program (and log the reason)Statement blocks are indicated by a keyword-keyword combination, for example, if-endif or for-endfor (no { or } here).
Parentheses around conditions are allowed but are unnecessary (and in certain obscure circumstances can even cause syntax errors; it's best to omit them). Below, the left-hand statement has the same effect as the right-hand:
if <cond> if (<cond>) elif <cond> elif (<cond>) while <cond> while (<cond>) until <cond> until (<cond>) for <init> <cond> <incr> for (<init> <cond> <incr>)
![]() | next page ![]() |