Sign in to follow this  
Followers 0
BinaryBrother

For...Next...

8 posts in this topic

#1 ·  Posted (edited)

I know it's not ideal to write a script that breaks a For loop early... but is it possible? Is it possible to 'Exit' that particular For loop?

For $N = 0 To 100
     If $ManOnMoon = True Then
          _DoStuff
          More stuff lala
          If @Error Then
               StartOver DONT EXECUTE further...
          EndIf
          More stuff here   ; <---- That line should not be executed if @Error...
     EndIf
Next

Oh, and I know about ExitLoop... But I have my For loop inside a While loop... If I use ExitLoop... It exits all the way back... :P

Edited by BinaryBrother

Share this post


Link to post
Share on other sites



ContinueLoop I guess.

Share this post


Link to post
Share on other sites

Also remember ExitLoop has an optional loop level

ExitLoop [level]

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I looked at that a hundred times... I thought the way it worked it Only continued the loop if that was true... I can't believe I asked a question so stupid... Sorry guys...

:unsure:

I thought it worked right reverse of that... Again, I'm sorry... :D :D :(

ExitLoop breaks it entirely, I just need to finish that 1 particular instance... Thanks so much!

This is why I wish we could delete our own topics... I wrote a 2,000 line script for a company! It used some hell-asiously terrible code, but still.. It worked like it was supposed to... No-matter how good I get at AutoIt... This topic will always be here... To haunt me...

It's actually more embarrassing then you would think... I even read the help-file for like 45 minutes making sure I wasn't missing something before I clicked 'Post'...

:P

Edited by BinaryBrother

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I looked at that a hundred times... I thought the way it worked it Only continued the loop if that was true... I can't believe I asked a question so stupid... Sorry guys...

:P

I thought it worked right reverse of that... Again, I'm sorry... :unsure::D:D

We appreciate people who try...

... We all make mistakes ( at least I do )

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

I can't get the same result you did though because ExitLoop should equal ExitLoop(1) and should exit out of the FOR but you say you got it to do it for both. I did a simply script in which I create a temp IE with the name Test and this script

#include <IE.au3>
Local $oIE

$bContinue = True
While 1
    For $N = 0 To 100
        If $bContinue = True Then
            $oIE = _IEAttach("Test")
            If @error Then
                ExitLoop
            EndIf
            MsgBox(0, "", @error)
        EndIf
    Next
WEnd

I got a error report as soon as I made the window disappear and made sure there was no Test on any of my browser screen. The ExitLoop exited the FOR in this step


0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Share this post


Link to post
Share on other sites

I had an 'Exit' right after next, inside a while loop, before WEnd... It was supposed to read 5 lines in a file and then exit, I kept messing up and reading the wrong file, so I added error handling... :P

But upon @Error & ExitLoop, it exited the entire app... I may have just had something somewhere wrong, but ContenueLoop was EXACTLY what I needed... I even read the documentation like 3 or 4 times over it.. I had the concept backwards... The example looks like this...

;Print all numbers from 1 to 10 except number 7
For $i = 1 to 10
    If $i = 7 Then ContinueLoop
    MsgBox(0, "The value of $i is:", $i)
Next

;Example of using level is needed.

I totally missed the 'note' at the top, and read the script... Well, to me it looked like it only showed a message box for "7" meaning that it did not pass 'ContinueLoop' unless $I = 7... Which was backwards to it's intended usage... :unsure:

Share this post


Link to post
Share on other sites

I see then, yes I though you wanted the print all till you get a error then exit the loop but then keep in the while. However END does play a major role here, lol.


0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0