| View previous topic :: View next topic |
| Author |
Message |
adamrgolf
Joined: 28 Dec 2006 Posts: 362
|
Posted: Tue Jul 01, 2008 10:53 pm Post subject: New AHK user help (conditional loops) |
|
|
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 |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Tue Jul 01, 2008 11:13 pm Post subject: |
|
|
| Code: | Loop, 5 {
i++ ; Note -> There is a automatic counter variable: A_Index
} |
 _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
adamrgolf
Joined: 28 Dec 2006 Posts: 362
|
Posted: Tue Jul 01, 2008 11:22 pm Post subject: |
|
|
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 |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Tue Jul 01, 2008 11:33 pm Post subject: |
|
|
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
} |
 _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
adamrgolf
Joined: 28 Dec 2006 Posts: 362
|
Posted: Tue Jul 01, 2008 11:50 pm Post subject: |
|
|
| Yea, i was assuming he would set a value for x prior to the loop |
|
| Back to top |
|
 |
sethl
Joined: 02 Jul 2008 Posts: 1
|
Posted: Wed Jul 02, 2008 4:41 pm Post subject: |
|
|
| 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 |
|
 |
adamrgolf
Joined: 28 Dec 2006 Posts: 362
|
Posted: Wed Jul 02, 2008 7:35 pm Post subject: |
|
|
hey seth, welcome to the forums and good luck with ahk  |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Wed Jul 02, 2008 7:39 pm Post subject: |
|
|
Welcome seth.. Happy Scripting!  _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
|