YouTip LogoYouTip

Perl Foreach Loop

# Perl foreach Loop [![Image 4: Perl Loops](#) Perl Loops](#) The Perl foreach loop is used to iterate over the values of a list or collection variable. ### Syntax The syntax format is as follows: foreach var (list) {...} ### Flowchart ![Image 5: Perl foreach Loop](#) ## Example #!/usr/bin/perl@list = (2, 12, 36, 42, 51); # Execute foreach loop foreach$a(@list){print"a value is: $an"; } Executing the above program, the output result is: a value is: 2 a value is: 12 a value is: 36 a value is: 42 a value is: 51 [![Image 6: Perl Loops](#) Perl Loops](#)
← Bootstrap5 TablesBootstrap5 Typography β†’