Jump to content
Sign in to follow this  
millisys

Exclude For Next loop

Recommended Posts

millisys

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

Share this post


Link to post
Share on other sites
millisys

Hi John,

I am looking for a solution that will work with nested folders. If I try that syntax with a nested loop it throws a syntax error.

Share this post


Link to post
Share on other sites
Nessie

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

Share this post


Link to post
Share on other sites
JohnOne

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.

Share this post


Link to post
Share on other sites
millisys

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.

:)

Share this post


Link to post
Share on other sites
Nessie

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

Share this post


Link to post
Share on other sites
millisys

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?

Share this post


Link to post
Share on other sites
Nessie

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

Share this post


Link to post
Share on other sites
millisys

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

Share this post


Link to post
Share on other sites
kylomas

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
millisys

Hi John,

I agree, I am trying to achieve a 1,1,1,1,1 then 1,1,1,1,2 pattern, but sometimes skip creation of a number generating loop.

Edited by millisys

Share this post


Link to post
Share on other sites
millisys

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

Share this post


Link to post
Share on other sites
kylomas

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

Share this post


Link to post
Share on other sites
millisys

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

Share this post


Link to post
Share on other sites
millisys

Hi JohnOne,

I will assemble some sample code and data to illustrate what I am trying to achieve.

Thank you.

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  

×