Perl Tutorials -Part 43- Nested loops

Posted on June 2, 2010. Filed under: Perl Tutorials |


#perl example of nested loop
@names = ('Amina', 'Bhimsen', 'Charles', 'Damien');

for ($i = 0; $i <6; $i++)
{
        for ($k = 1; $k < 6; $k++)
        {
              print "$i multiplied by $k makes ". $i * $k . " \n";
        }
}

Output:

0 multiplied by 1 makes 0
0 multiplied by 2 makes 0
0 multiplied by 3 makes 0
0 multiplied by 4 makes 0
0 multiplied by 5 makes 0
1 multiplied by 1 makes 1
1 multiplied by 2 makes 2
1 multiplied by 3 makes 3
1 multiplied by 4 makes 4
1 multiplied by 5 makes 5
2 multiplied by 1 makes 2
2 multiplied by 2 makes 4
2 multiplied by 3 makes 6
2 multiplied by 4 makes 8
2 multiplied by 5 makes 10
3 multiplied by 1 makes 3
3 multiplied by 2 makes 6
3 multiplied by 3 makes 9
3 multiplied by 4 makes 12
3 multiplied by 5 makes 15
4 multiplied by 1 makes 4
4 multiplied by 2 makes 8
4 multiplied by 3 makes 12
4 multiplied by 4 makes 16
4 multiplied by 5 makes 20
5 multiplied by 1 makes 5
5 multiplied by 2 makes 10
5 multiplied by 3 makes 15
5 multiplied by 4 makes 20
5 multiplied by 5 makes 25
Advertisements

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: