AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Breaking Inner Loop of the n-th level

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Bytales



Joined: 06 Sep 2008
Posts: 84

PostPosted: Mon Sep 08, 2008 10:54 am    Post subject: Breaking Inner Loop of the n-th level Reply with quote

Ok, lets say i'm doing the following logic code

Code:

Check Statement A
   If True
      Check Stament B
         If True
            Make Step C
            Make Step D
            Make Step E
            Make Step F
         If False
            Make Step D
            Make Step E
            Make Step F
   If False
      Check Statement B
         If True
            Make Step F
         If False
            Make Step E
            Make Step F


After the script does Step F, i need the sistem to re-evaluate Stament A.
If i enclose all the script in a loop and put a continue after each step F, will it work ? Because i know a continue placed in a loop restarts a loop, But this is on hell of a loop, each step and statement beeing extremely huge, esspecialy step E wich will probably be 1mb of text !

And speaking of that;
Isn't there a way to write once each step in the script, and then use the above code to relate to the allready written steps

For instance
Step C
{
bla bla bla
}

Step D
{
bla bla bla
}
etc.

And then used the simplified code above, and everithing is ok. ?
Aren't those called soubrutines or something. ?
I mean, describing the soubrutine once, and whenever i need to run that soubrutine, just write it's name.
Can this be done ?

Now i realized this is not a loop in a loop in a loop scenario.
But just in case i;ll ever make a loop1 in a loop2 in a loop3, and i put a continue in the inner most loop, which is loop 1, will loop 1 restart or loop 3 (outer most)restart ?
Back to top
View user's profile Send private message
Serenity



Joined: 07 Nov 2004
Posts: 1272

PostPosted: Mon Sep 08, 2008 1:17 pm    Post subject: Reply with quote

You can use Gosub for both, you can also use functions:

Code:
Check_A:
Check Statement A
   If True
      Check Stament B
         If True
            Gosub, Step_C
            Step_D()
            Make Step E
            Make Step F
            Gosub, Check_A
         If False
            Make Step D
            Make Step E
            Make Step F
   If False
      Check Statement B
         If True
            Make Step F
         If False
            Make Step E
            Make Step F
         
StepC:
; your code here
Return         

StepD() {
; your code here
}

_________________
"Anything worth doing is worth doing slowly." - Mae West
Back to top
View user's profile Send private message Visit poster's website
Bytales



Joined: 06 Sep 2008
Posts: 84

PostPosted: Mon Sep 08, 2008 6:33 pm    Post subject: Reply with quote

Nice, so i can write the "Subrutine" only once, and it is executed as many times as needed
Back to top
View user's profile Send private message
Bytales



Joined: 06 Sep 2008
Posts: 84

PostPosted: Tue Sep 09, 2008 6:22 pm    Post subject: Reply with quote

Code:

loop, ;loop A
{
;body loop
loop, ;loop B
{
;body loop
}
;body loop
}


I know using continue restarts the loop
I need to use a continue inside the loop B to restart loop A
How can i do that ?
I i put a continue in loop B, it will restart loop B, not loop A
Back to top
View user's profile Send private message
Sivvy



Joined: 21 Jul 2008
Posts: 726
Location: Calgary, AB, Canada

PostPosted: Tue Sep 09, 2008 7:08 pm    Post subject: Reply with quote

Code:
loop, ;loop A
{
;body loop
loop, ;loop B
{
;body loop
Break
}
Continue
;body loop
}


No matter what, Loop "B" will be executed, so why not put a Break in Loop "B", and a Continue on the first line after Loop "B" ends?

Or you can go into the HelpFile, and look up "GoSub". That'll definitely do it for you.
Back to top
View user's profile Send private message
Bytales



Joined: 06 Sep 2008
Posts: 84

PostPosted: Tue Sep 09, 2008 9:16 pm    Post subject: Reply with quote

I too was thinking of breaking loop B, and put a continue right after that, outside of loop B ofcourse.
It seems i was right ! You thought the same thing
Back to top
View user's profile Send private message
Sivvy



Joined: 21 Jul 2008
Posts: 726
Location: Calgary, AB, Canada

PostPosted: Tue Sep 09, 2008 9:36 pm    Post subject: Reply with quote

Problem with that is... The code at the end of Loop "A" wouldn't get executed. You would need to essentially make a boolean value (On/Off or True/False) and have a couple If statements in and out of the Loop "B" for that to work. Honestly, I would really consider looking at "GoSub" in the HelpFile. It is easy to use...
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1424

PostPosted: Tue Sep 09, 2008 9:52 pm    Post subject: Reply with quote

Quote:
But this is on hell of a loop, each step and statement beeing extremely huge, esspecialy step E wich will probably be 1mb of text !


If its 1mb of text then youre doing it wrong
Back to top
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 2342

PostPosted: Wed Sep 10, 2008 2:06 am    Post subject: Reply with quote

tic wrote:
If its 1mb of text then youre doing it wrong

ROFL... but I agree. Smart use of functions/subroutine will minimize repetitive code significantly.

On a side note: timers, recursion, and goto are other repetition mechanisms that can be used instead of loops (but be careful!)
_________________
My Home Thread
Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Back to top
View user's profile Send private message
Bytales



Joined: 06 Sep 2008
Posts: 84

PostPosted: Wed Sep 10, 2008 2:40 am    Post subject: Reply with quote

[VxE] wrote:
tic wrote:
If its 1mb of text then youre doing it wrong

ROFL... but I agree. Smart use of functions/subroutine will minimize repetitive code significantly.

On a side note: timers, recursion, and goto are other repetition mechanisms that can be used instead of loops (but be careful!)


Ok, i guess i was exagerating about 1 mb of text.
But even so, now that i have learned the subroutines thing, i have made everithing into subroutines, and call the subrutine whenever i need something done !
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group