AutoHotkey Community

It is currently May 26th, 2012, 12:07 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: September 8th, 2008, 11:54 am 
Offline

Joined: September 6th, 2008, 3:11 pm
Posts: 84
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 ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2008, 2:17 pm 
Offline

Joined: November 8th, 2004, 12:46 am
Posts: 1271
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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2008, 7:33 pm 
Offline

Joined: September 6th, 2008, 3:11 pm
Posts: 84
Nice, so i can write the "Subrutine" only once, and it is executed as many times as needed


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2008, 7:22 pm 
Offline

Joined: September 6th, 2008, 3:11 pm
Posts: 84
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2008, 8:08 pm 
Offline

Joined: July 21st, 2008, 4:16 pm
Posts: 726
Location: Calgary, AB, Canada
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2008, 10:16 pm 
Offline

Joined: September 6th, 2008, 3:11 pm
Posts: 84
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2008, 10:36 pm 
Offline

Joined: July 21st, 2008, 4:16 pm
Posts: 726
Location: Calgary, AB, Canada
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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2008, 10:52 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2008, 3:06 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3329
Location: Simi Valley, CA
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!)

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2008, 3:40 am 
Offline

Joined: September 6th, 2008, 3:11 pm
Posts: 84
[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 !


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Google Feedfetcher, kkkddd1, StepO, Yahoo [Bot] and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group