Is there any command to come out of the loop?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • susinthaa
    New Member
    • Jun 2007
    • 30

    Is there any command to come out of the loop?

    Hi,
    I tried the following code.I m trying 2 compare two strings.If its not matches, the while loop has to continue and if it matches, it will come out of the while loop.
    But In my code, Even it matches the while loop continuing.
    can anybody tell me where I am wrong?

    [CODE=perl]
    $flag=1;
    LINEP:
    while ($flag==1) {
    print"Enter the lun name\n";
    chomp($lunname= <stdin>);
    foreach $line (@weblist) {
    if ($line =~ m/$lunname/i) {
    $flag=0;
    print " found";
    redo LINEP;
    } else {
    $flag=1;
    redo LINEP;
    }

    }
    }
    [/CODE]

    Thanks and Regards,
    susi
    Last edited by miller; Jun 28 '07, 07:18 PM. Reason: Code Tag and ReFormatting
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    You posted in the perl articles area.

    If you want out of the loop, why are you using "redo"? Maybe you should use "last".

    if ($line =~ m/$lunname/i) {
    print " found";
    last LINEP;

    }

    Comment

    • susinthaa
      New Member
      • Jun 2007
      • 30

      #3
      Hi Kevin,

      Yes, Last is working fine to come out of the loop
      But I want to loop again for invalid inputs.

      Thanks,
      Susi.

      Comment

      • alcazar
        New Member
        • Jun 2007
        • 10

        #4
        Use "next" to go back to beginning of loop

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          Originally posted by susinthaa
          Hi Kevin,

          Yes, Last is working fine to come out of the loop
          But I want to loop again for invalid inputs.

          Thanks,
          Susi.
          last - exits loop
          next - goes to next iteration of loop
          redo - does the same loop over again

          you figure out which loop control you need to use.

          Comment

          • susinthaa
            New Member
            • Jun 2007
            • 30

            #6
            Hi ,

            Thanks for your valuable information.
            Now I understand.Wher e I have to use these.

            Thanks and Regards,
            Susi.

            Comment

            Working...