#!/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,

0 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
when i need it to do this
system 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.
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. Cheers


In reply to 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.