ajl412860 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; my @a1 = qw(My name is Andrew); my @a2 = qw(My dog named Andrew); my $i; my $a = 0; my $s = 0; my $z = 0; my $aa; my $ss; my $n = "\n"; my $t = "\t"; foreach my $a1 (@a1){ $i++; #print $a1 . "\n"; } First:for($a = 0; $a <= $i; $a++){ Second:for($s = 0; $s <= $i; $s++){ my $d = 0; print $a.$t; print $s.$n; if($a!=$s){ print "Yes.->".$a.$s.$n; last} print "system command \$a $a, then for \$s $s".$n; $d++; } }
What I am trying to do here, use this nested for loop to get numbers that don't match. I need this to be continous, as this is a blueprint for another project. Now it appears that when I do the code, I get this,
when i need it to do this0 0 system command $a 0, then for $s 0 0 1 Yes.->01 1 0 Yes.->10 2 0 Yes.->20 3 0 Yes.->30 4 0 Yes.->40
My problem is that I can't seem to get the script to loop through the for loops after the $_'s go through the boolean statements. It seems the boolean statements cause the for loops to not progress. I need to have the boolean statements to get unequal numbers. This is the best I can explain it. Any tips. Cheerssystem command $a 0, then for $s 0 system command $a 0, then for $s 1 system command $a 0, then for $s 2 system command $a 0, then for $s 3 system command $a 0, then for $s 4 system command $a 1, then for $s 0 system command $a 1, then for $s 1 system command $a 1, then for $s 2 .... and so on and so on.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to repeat a if else statement in a nested for loop
by graff (Chancellor) on Jun 19, 2015 at 01:46 UTC | |
|
Re: how to repeat a if else statement in a nested for loop
by AnomalousMonk (Archbishop) on Jun 19, 2015 at 00:55 UTC | |
|
Re: how to repeat a if else statement in a nested for loop
by Random_Walk (Prior) on Jun 19, 2015 at 06:32 UTC | |
by AnomalousMonk (Archbishop) on Jun 19, 2015 at 16:11 UTC | |
|
Re: how to repeat a if else statement in a nested for loop
by Laurent_R (Canon) on Jun 19, 2015 at 06:35 UTC |