Jump to content
Sign in to follow this  
Miranda

For loop with changing Step value

Recommended Posts

Miranda

unfortunately this:

$step=1
for $i=1 to 1000 step $step
Tooltip($i)
Sleep(50)
$step+=1
Next

Doesn't work (or well, the step the for loop uses is always 1)

Is there a way to get this to work?

Share this post


Link to post
Share on other sites
JLogan3o13

Errr, your loop uses 1 because you defined $step to be 1. This works just fine for me, regardless of the number I use for $step:

$step = 14

For $i = 0 To 10000 Step $step
   MsgBox(0, "", $i)
Next
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
kylomas

Miranda,

From the help file...

If stepVal or stop is a variable, its value is only read the first time the loop executes.

kylomas

P.S. I got caught on this once too!


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Melba23

Miranda,

And AutoIt also only reads the loop limit values once on entry as well - which is why if you loop through an array and delete some of the elements, you must always start from the bottom and work up. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
SandelPerieanu

try this:

$step = 1
$i=1
Do
    Tooltip($i)
    Sleep(50)
    $step += 1
    $i += $step
Until $i>=1000

Share this post


Link to post
Share on other sites
Mechaflash

loopty-loop

$step = 1
$count = 1
While 1
  for $i = $count to 1000 Step $step
    $step=1
    Tooltip($i)
    Sleep(50)
    $count+=$step
    $step+=1
    ContinueLoop(2)
  Next
WEnd

not tested... think it'll work =D

http://qkme.me/3to2md

Edited by Mechaflash

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites
kylomas

Miranda,

This

for $i=1 to 1000 step 2
Tooltip($i)
Sleep(50)
Next

looks functionally equivalent to your OP.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Mechaflash

Miranda,

This

for $i=1 to 1000 step 2
Tooltip($i)
Sleep(50)
Next

looks functionally equivalent to your OP.

kylomas

I think she's hoping to keep increasing step throughout the loop and the loop registering the change in step

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites
kylomas

I think she's hoping to keep increasing step throughout the loop and the loop registering the change in step

Yes, but she's increasing by "1". That is why I suggested "STEP 2". Any other value and I'm with you..


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Mechaflash

When step is 2 and it goes through the loop, then step is 3... then 4... then 5... etc.

EDIT: But it's possible the OP may not have been clear either so either of us may be right/wrong

EDIT2: Or even both of us may be wrong... maybe we offered her a lounging chair and a rocking chair when OP wanted a Couch =D

Edited by Mechaflash

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites
kylomas

Build her a condo...then she has it all...


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Miranda

You guys are hilarious :P

Thanks a lot for all the answers!

The first post was only a proof of concept, but I didn't think of just using do and incrementing it manually, which works perfectly :)

Share this post


Link to post
Share on other sites
czardas

SandelPerieanu's answer is the best so far. Anyway, it's easy enough to modify the iteration count.

Local $iCount = 0
For $i = 1 To 1000
    ; Code here
    ConsoleWrite($i & @LF)
    $i += $iCount
    $iCount += 1
Next

Share this post


Link to post
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
Sign in to follow this  

×