You really need to try harder to explain it, because so far, you seem to be contradicting yourself. First you say that you're "trying ... to get numbers that don't match", and then you say "I need it to do this" and you give sample output where it makes no difference whether the numbers match or not. So which is it?

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"):

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++; } }
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.

Proper indentation is important, especially when you're already confused about other things.


In reply to Re: how to repeat a if else statement in a nested for loop by graff
in thread how to repeat a if else statement in a nested for loop by ajl412860

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.