-1

I am working on exiting VBScript code having with..end with loop. I need break/exit the loop on a certain condition, how can I break or exit from With..End With loop in VBScript

Thanks in advance

MrX
  • 1
  • 1
  • 2
  • You simply add `Exit Do` after the condition you are checking. – user692942 Apr 09 '19 at 14:46
  • Nope. It's not while loop. – MrX Apr 09 '19 at 15:13
  • @MrX You're going to have to actually show the code to get any help. I don't think `With` should be used for a loop in any case, so you will need to explain how you are using it. – Dave Apr 09 '19 at 15:25
  • `With` is definitely not a loop construct. Loops in VBScript are various forms of `Do`, `While` or `For` statements. – user692942 Apr 09 '19 at 17:15

1 Answers1

1

With is not a looping construct. Something similar to this as an example will work as I credit Lankymart with stating above:

This is designed to loop 10 times but will exit on the If/Then condition of 5 and the Exit Do will execute

Do While x < 10
    x = x + 1
    wscript.echo x
    if x = 5 then Exit Do
Loop

or...

For x = 0 to 10

    x = x + 1
    wscript.echo x
    if x = 5 then Exit For

Next
svstackoverflow
  • 665
  • 6
  • 19