Jump to content

for...to....step....next


Recommended Posts

hi everybody

can u show me again this word, STEP

i don't understant that word

may u show me abvious , please

thanks so much

it allows you to choose the increment of the variable in the For...Next loop

EX:

For $i = 5 to 0 step -1
Msgbox(0,"",$i)
Next

This code will count from 5 down to 0. If we hadn't had the "step -1" in there, it would be trying to count up by 1(default) to get to zero which would obviously never happen.

Link to comment
Share on other sites

hi everybody

can u show me again this word, STEP

i don't understant that word

may u show me abvious , please

thanks so much

Are you asking for an example?

For $i = 1 to 100 Step 10

Consolewrite(@crlf & $i)

Next

Consolewrite(@crlf & "---------------")

For $i = 100 to 1 Step -10

Consolewrite(@crlf & $i)

Next

You can help! Donate to AutoIt! or, visit ClimatePREDICTION.netMy posts:Travian Bot Example (100+ servers) BETAHow to Host you code/app for free! (unlimited team number) (Public or Private)"Sir, we're surrounded!" "Excellent. We can attack in any direction!"
Link to comment
Share on other sites

it allows you to choose the increment of the variable in the For...Next loop

EX:

For $i = 5 to 0 step -1
Msgbox(0,"",$i)
Next

This code will count from 5 down to 0. If we hadn't had the "step -1" in there, it would be trying to count up by 1(default) to get to zero which would obviously never happen.

if i write

for $n = 5 to 0

MSgbox(0,"",$n)

Next [code=auto:0]

what's happen , i can see the number from 0 to 5

Why ?

Link to comment
Share on other sites

it allows you to choose the increment of the variable in the For...Next loop

EX:

For $i = 5 to 0 step -1
Msgbox(0,"",$i)
Next

This code will count from 5 down to 0. If we hadn't had the "step -1" in there, it would be trying to count up by 1(default) to get to zero which would obviously never happen.

if i write

for $n = 5 to 0 
MSgbox(0,"",$n)
Next

what's happen , i can not see the number from 0 to 5

Why ?

Edited by o0o0ohanhanngao0o0o
Link to comment
Share on other sites

if i write

for $n = 5 to 0 
MSgbox(0,"",$n)
Next

what's happen , i can not see the number from 0 to 5

Why ?

Because unless a "step" is defined, it starts at the first number (in this case, 5) and counts up until it gets to the second number (in this case, 0) obviously, you can't count up to zero from 5, so the script fails. Edited by Paulie
Link to comment
Share on other sites

it allows you to choose the increment of the variable in the For...Next loop

EX:

For $i = 5 to 0 step -1
Msgbox(0,"",$i)
Next

This code will count from 5 down to 0. If we hadn't had the "step -1" in there, it would be trying to count up by 1(default) to get to zero which would obviously never happen.

why do u use -1 at step but why dont u use 2 or 3 or ........

Link to comment
Share on other sites

  • Moderators

Step moves forward or backward the number you provide for it.

Step with a positive number after: Step 1 or Step 2 etc... Will move forward 1 or 2 in a For Next loop.

Step with a negative number after: Step -1 or Step -2 etc... Will move backward 1 or 2 in the For Next loop.

So if I want skip 2 at a time forward:

For $i = 1 To 10 Step 2
    MsgBox(64, "Info", $i)
NextoÝ÷ ØÈÁ©í¶$µ«bæÚrL­ÛºÚ"µÍÜ   ÌÍÚHHLÈHÝHÙÐÞ
    ][ÝÒ[É][ÝË ÌÍÚJB^

Note the larger integer first in the For next 10 Then 1, Since it's larger first, I use the negative approach demonstrated.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...