The foreach loop is used for iterating arrays/lists.
Syntax of foreach loop:
foreach var (list) { statement(s); }
Flow of Execution of the foreach Loop
In foreach loop, the loop continues execution until all the elements of the specified array gets processed.
Example
#!/usr/local/bin/perl @friends = ("Ajeet", "Tom", "Steve", "Lisa", "Kev"); foreach $str (@friends){ print "$str\n"; }
Output:
Ajeet Tom Steve Lisa Kev
Leave a Reply