tags:

views:

893

answers:

2

Hi, Can anyone please tell me if there is anyway by which i can exit from a while loop when a certain condition is true

when i tried this below,i get some errors

     num = 0
       while(num<10)


         if(status = "Fail") then
         exit while

         end if
      num = num+1
     wend

I get some errors.Is there any work around for this.

+1  A: 

what about changing the while loop to a do while loop

and exit using

Exit Do
rahul
changing my while loop to do while loop will make my code even more complex.So i just found a workaround in which if u want to exit from a while loop using vbscripts,whenever the condition is set just set the while loop to the non matching condition of the loop.For eg: while(num<10) if(status = "Fail") then num = 10'here u just set the condition so that while lop fails end if
+5  A: 

VBScript's While loops don't support early exit. Use the Do loop for that:

num = 0
do while (num < 10)
  if (status = "Fail") then exit do
  num = num + 1
loop
Helen