Jump to content

Exclude For Next loop


Recommended Posts

Hi,

I am trying to figure out how to configure some nested loops so that based upon user preference a user can choose not to 'run' a loop. I am posting up a simple example in case in the hopes that there is a simple answer.

I imagine I could use a variable once inside the loop to exitloop, but I was hoping for syntax that would allow me to completely prevent the loop from running.

In this example I tried using a simple if...then statement but it doesn't work. :(

Thank you

$includeloop2 = 0

for $loop1 = 1 to 3
    if $includeloop2 = 1 then for $loop2 = 1 to 3
        for $loop3 = 1 to 3
        Next
    Next
Next
Link to comment
Share on other sites

Plase can you post the full code? And explain better when you want to skyp this fantomatic loop?

Hi!

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

Your code will.

for $loop1 = 1 to 3
    if $condition2  then 
        for $loop2 = 1 to 3
            If $condition3 Then
                for $loop3 = 1 to 3
                Next
            EndIf
        Next
    Endif
Next

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Thank you so much JohnOne and Nessie,

I see my mistake, I was over-complicating things by if...then conditioning the For and if...then conditioning the Next in my actual script instead of just using an 'if' before the For and in 'endif' after the Next.

:)

Link to comment
Share on other sites

The important is that you have solved your problem ;)

Hi!

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

Hi JohnOne,

I put the script into my actual script and noticed that it has the affect of shutting down all subsequent loops. My goal is to just shut down the one loop with a conditional statement and allow subsequent loops to run. For example, in my actual script I have 12 nested loops, sometimes I want the loop to function as loop 2, sometimes as loop 11. I would like to use a conditional statement to turn one off and turn the other one on.

I have tried all combinations of if...then statements but they all end up shutting down the subsequent loops.

Is this possible?

Link to comment
Share on other sites

Have you tried ExitLoop setted on different level? Like ;

For $i = 0 To 5
    For $x = 0 To 5
        For $y = 0 To 5
            If $condition Then
                ExitLoop 2
            EndIf
        Next
    Next
Next
Hi! Edited by Nessie

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

Hi Nessie,

I have tried using ExitLoop with the Level parameter but it seems to have the effect of shutting down the subsequent loops. What I am trying to achieve is syntax that would process loop1, skip over loop2, and then go to loop3.

I know this code isn't correct but this is what I have in mind:

$excludeloop2 = 1 

for $loop1 = 1 to 3     
    if $excludeloop2 = 1 then ;then skip this loop and go to loop3
        for $loop2 = 1 to 3
    EndIf           
            for $loop3 = 1 to 3         
            Next  
    if $excludeloop2 = 1 then ;then skip this loop and go to loop3  
        Next 
    EndIf
Next
Link to comment
Share on other sites

millisys,

Like this?

$includeloop2 = 1

for $loop1 = 1 to 3
    ConsoleWrite('loop1 iteration' & @LF)
    if $includeloop2 = $loop1 then
        for $loop2 = 1 to 3
            ConsoleWrite('loop2 iteration' & @LF)
        next
    endif
    for $loop3 = 1 to 3
        ConsoleWrite('loop3 iteration' & @LF)
    Next
Next

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Hi kylomas,

Hmm, I will have to experiment with it to see if it will accomplish the intended goal. My concern is if:

for $a = 1 to 5
    for $b = 1 to 5
    next

    for $c = 1 to 5
    next

    for $d = 1 to 5
    next

    for $e = 1 to 5
    next
next

generates the same result as this:

for $a = 1 to 5
    for $b = 1 to 5
        for $c = 1 to 5
            for $d = 1 to 5
                for $e = 1 to 5
                next
            next
        next
    next
next
Link to comment
Share on other sites

millisys,

 

Hi kylomas,

Hmm, I will have to experiment with it to see if it will accomplish the intended goal. My concern is if:

for $a = 1 to 5
    for $b = 1 to 5
    next

    for $c = 1 to 5
    next

    for $d = 1 to 5
    next

    for $e = 1 to 5
    next
next

generates the same result as this:

for $a = 1 to 5
    for $b = 1 to 5
        for $c = 1 to 5
            for $d = 1 to 5
                for $e = 1 to 5
                next
            next
        next
    next
next

These return completely different results as you would see if you ran them with like this. 

for $a = 1 to 5
    ConsoleWrite('loop a' & @LF)
    for $b = 1 to 5
        ConsoleWrite(@tab & 'loop b' & @LF)
    next

    for $c = 1 to 5
        ConsoleWrite(@tab & @tab & 'loop c' & @LF)
    next

    for $d = 1 to 5
        ConsoleWrite(@tab & @tab & @tab & 'loop d' & @LF)
    next

    for $e = 1 to 5
        ConsoleWrite(@tab & @tab & @tab & @tab & 'loop e' & @LF)
    next
next

ConsoleWrite('! second example' & @LF)

for $a = 1 to 5
    ConsoleWrite('loop a' & @LF)
    for $b = 1 to 5
        ConsoleWrite(@tab & 'loop b' & @LF)
        for $c = 1 to 5
            ConsoleWrite(@tab & @tab & 'loop c' & @LF)
            for $d = 1 to 5
                ConsoleWrite(@tab & @tab & @tab & 'loop d' & @LF)
                for $e = 1 to 5
                    ConsoleWrite(@tab & @tab & @tab & @tab & 'loop e' & @LF)
                next
            next
        next
    next
next

You agree with J1 and then offer this?

 but sometimes skip creation of a number generating loop. 

and this

sometimes I want the data to appear as:

1apple,1pear,1orange,1kiwi
1apple,1pear,1orange,2kiwi

othertimes I want the data to appear as:

1apple,1pear,1kiwi,1orange
1apple,1pear,1kiwi,2orange

 

"sometimes"...?

 

Good Luck,

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Hi kylomas,

Sorry for the 'sometimes' vagueness.

By sometimes I just meant that I would like to allow the user the ability to select if they want Kiwis to be a subset of Oranges or if they want Oranges to be a subset of Kiwis because it effects the way that the data is organized.

Edited by millisys
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...