Perl foreach cycle


Release date:2023-10-14 Update date:2023-10-21 Editor:admin View counts:222

Label:

Perl foreach cycle

Perl foreach loop is used to iterate over the value of a list or collection variable.

Grammar

The syntax format is as follows:

foreach var (list) {
...
}

Flow chart

Image0

Example

#!/usr/bin/perl@list=(2,12,36,42,51);# executeforeach
circulateforeach$a(@list){print"a's value is:$a\\n";}

Execute the above program, and the output is as follows:

The value of a is: 2
The value of a is: 12
The value of a is: 36
The value of a is: 42
The value of a is: 51

Powered by TorCMS (https://github.com/bukun/TorCMS).