Exit a while loop in VBS/VBA Exit a while loop in VBS/VBA vba vba

Exit a while loop in VBS/VBA


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

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


what about changing the while loop to a do while loop

and exit using

Exit Do


While Loop is an obsolete structure, I would recommend you to replace "While loop" to "Do While..loop", and you will able to use Exit clause.

check = 0 Do while not rs.EOF    if rs("reg_code") = rcode then       check = 1       Response.Write ("Found")       Exit do   else       rs.MoveNext     end if Loop if check = 0 then    Response.Write "Not Found" end if}