in reply to how to repeat a if else statement in a nested for loop
You might be getting confused by your poor use of indentation, and your irregular use of line breaks vs. spaces between statements. Here's how the nested "for" loops in the OP script look when formatted in the "normal" Perlish way (and with a normal use of "print"):
Having "last" inside the "if" block means that as soon as $a and $s have different values, you go directly to the next value of $a. When $a is 0, you get two iterations on $s, but after that (with $a > 0) you exit the inner loop immediately (because $s always start at 0, which is always different from $a), so you never reach the "system command" print statement.for ( $a = 0; $a <= $i; $a++ ) { for ( $s = 0; $s <= $i; $s++ ) { my $d = 0; print "$a\t$s\n"; if ( $a != $s ) { print "Yes.->$a$s\n"; last; } print "system command \$a $a, then for \$s $s".$n; $d++; } }
Proper indentation is important, especially when you're already confused about other things.
|
|---|