Multiple conditions on a while loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kavithapotnuru
    New Member
    • Aug 2007
    • 1

    Multiple conditions on a while loop

    Hi All,

    Can anyone help me how to give multiple conditions in a while loop in perl.

    For example i have a while loop for which the value of a variable is A or B it should not enter in to the while loop.

    Basically i need the condition in the while loop should contains "||". Is it possible?

    If not can anyone suggest me an alternative

    Thanks & Regards
    Kavitha Potnuru
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Code:
    unless ($var eq  'A' || $var eq 'B') {
       while(some condition) {
          do something
       }
    }

    Comment

    • icemansan
      New Member
      • Aug 2007
      • 3

      #3
      u can give names to the loop and use them;;

      eg:-

      LOOP: foreach(@arr){
      while($_=~/^#/) {
      next LOOP;
      }
      }

      Comment

      • miller
        Recognized Expert Top Contributor
        • Oct 2006
        • 1086

        #4
        Kavitha,

        Your original premise is not entirely clear. However, maybe this is what you're talking about:

        [CODE=perl]
        while ($var ne 'A' && $var ne 'B') {
        # do something
        }
        [/CODE]

        - Miller

        Comment

        Working...