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 

New AHK user help (conditional loops)

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



Joined: 28 Dec 2006
Posts: 362

PostPosted: Tue Jul 01, 2008 10:53 pm    Post subject: New AHK user help (conditional loops) Reply with quote

I am getting a friend into AHK, he is in school learning C#, C++ etc, and sent me this email. I thought I'd post it here for your guys' help.

Thanks a ton!

Email:

Seth via email wrote:
Oh okay so if I want a loop to run off a condition it needs a nested if
statements inside the loop itself. What if I want a loop to run 5 times
would the code be...

Loop, 5{
Statement
}

Here is the statements I am use to running maybe you can figure it out
better what I'm trying to get at.

for( int i = 0; i < x; i++)
{
Statement
}
(i is for running the loop, i<x is to run the loop as long as i is less than
x, and i++ increments i every time it goes through the loop)
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5887

PostPosted: Tue Jul 01, 2008 11:13 pm    Post subject: Reply with quote

Code:
Loop,  5 {
i++ ; Note -> There is a automatic counter variable: A_Index
}


Smile
_________________
SKAN - Suresh Kumar A N
Back to top
View user's profile Send private message
adamrgolf



Joined: 28 Dec 2006
Posts: 362

PostPosted: Tue Jul 01, 2008 11:22 pm    Post subject: Reply with quote

So he wants

Code:
Loop, 5 {
If A_Index > x
   Break
}


And if he wanted a variable to reflect the count:

Code:
Loop, 5 {
i := A_Index              ;    or as long as i = 0 or null -- i++
If A_Index > x
   Break
}


correct?
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5887

PostPosted: Tue Jul 01, 2008 11:33 pm    Post subject: Reply with quote

x is not defined, so the loop would break on the first iteration.

The following would work:

Code:
Loop, % ( X := 5 ) {
If ( A_Index > X-1  )
     Break
}


Smile
_________________
SKAN - Suresh Kumar A N
Back to top
View user's profile Send private message
adamrgolf



Joined: 28 Dec 2006
Posts: 362

PostPosted: Tue Jul 01, 2008 11:50 pm    Post subject: Reply with quote

Yea, i was assuming he would set a value for x prior to the loop
Back to top
View user's profile Send private message
sethl



Joined: 02 Jul 2008
Posts: 1

PostPosted: Wed Jul 02, 2008 4:41 pm    Post subject: Reply with quote

X would be an independent variable such as a list or a pre-set number. Thanks for all the code samples should help me out a lot.
Back to top
View user's profile Send private message
adamrgolf



Joined: 28 Dec 2006
Posts: 362

PostPosted: Wed Jul 02, 2008 7:35 pm    Post subject: Reply with quote

hey seth, welcome to the forums and good luck with ahk Smile
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5887

PostPosted: Wed Jul 02, 2008 7:39 pm    Post subject: Reply with quote

Welcome seth.. Happy Scripting! Smile
_________________
SKAN - Suresh Kumar A N
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