September 2017
Beginner
402 pages
9h 52m
English
With the three keywords, while, until, and repeat, you can create loops that will be repeated a number of times defined by certain conditions. Let's start with the simplest case with a bare keywords while and until:
my $letter = 'a';while $letter ne 'd' { say $letter; $letter++;}
The body of the while loop will be repeated as long as the condition $letter ne 'd' is True. Here, the control over the variable is done in the body of the loop, while its header only controls the condition. If the condition is False before entering the loop, the body will not be executed, as shown in the following example:
my $letter = 't';while $letter le 'd' { # 't' is not less or equal then 'd'; say $letter; # body is not executed. ...
Read now
Unlock full access