First off, welcome to the Monastery. We hope you enjoy your stay.

Looking at your post, it is hard to understand what you are trying to achieve. Your specification is not so clear. But lets we what we can do...

my @a1 = qw(My name is Andrew); my @a2 = qw(My dog named Andrew);

First off you define two arrays of words, but later only one is used. Perhaps this is a clue...

foreach my $a1 (@a1){ $i++; #print $a1 . "\n"; }

Is this here to count the words in @a1 and set $i? If so we can skip it, and go an easier way later on

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

OK, so we have two loops, counting from 0 to $i. We have a $d in there that I don't think you use again. Then we print out a line, when the iterators are not equal. All very mysterious.

Wild Guess

Perhaps you are trying to compare the words in the lists? I see two word lists, and some initialisation based on the length of one of them. We may not even need nested loops. If that's what you are after, how about something like this...

use strict; use warnings; my @a1 = qw(My name is Andrew); my @a2 = qw(My dog named Andrew); my $i = 0; while ($a1[$i] and $a2[$i]) { # make sure something is in both arrays if ($a1[$i] ne $a2[$i]) { print "system command \$a1 $a1[$i], then for \$a2 $a2[$i]\n"; } else { print "# \$a1 $a1[$i], and \$a2 $a2[$i] are the same\n"; } $i++; }

Like I said, a wild guess. Please do update your specification, so we can help a little more

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

In reply to Re: how to repeat a if else statement in a nested for loop by Random_Walk
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.