Until

From LQWiki
Jump to navigation Jump to search

until is a loop construct in programming languages. It is the logical opposite of the while loop construct.

An until loop is expressed in English as, "until this condition evaluates true, execute this block". This is unbounded iteration, as the number of times the loop body will be executed is not known ahead of time. An infinite loop can result if the loop body does not correctly affect the loop condition.

For example, this Perl fragment discards lines from a file until a search pattern is found, a bit like grep:

$pattern = $ARGV[0];

$line = <> until $line =~ /$pattern/;
# ... do something with the matching line ...

See also