Sign in to follow this  
Followers 0
Dtvscrotes

loop with rotating variable

6 posts in this topic

I need some code that will loop with do and until. I want the variable inside of do and until to change each loop.

Example.

$1 = 1
$2 = 2
$endloop = 0

do 
    msgbox(1,"A","1 +" & $1 & "=" & 1+$1)
    $endloop = $endloop +  1
    until $endloop = 2

When i run this code a msgbox appears saying 1+1=1. The second time around(in the loop) I want it to use $2 instead of $1. Then it would repeat but with a new msgbox saying 1+2 = 3. I could go on with 1+3=4 etc.

I use the $endloop variable to end the loop once it loops for the second time.

I want $2 to be used the second time around. I was thinking maybe like a rotating variable that each time it is called upon it would change to a second state.

I looked into arrays and couldn't figure how they work but that may be the solution. I know i could type out the second loop and not use do/until but in my case I may want this to go through the process 1000 times or more so I don't want to copy/paste the msgbox line 1000 times and changing the variable each line.

Share this post


Link to post
Share on other sites



Or try something like this :)...

$counter = 1
Global $array[2] = ['1','2']

Do
    If Mod($counter, 2) = 0 Then;even
        MsgBox(0, 'Even: ' & $counter, $array[0])
        $array[0] += 1
    Else;odd
        MsgBox(0, 'Odd:' & $counter, $array[1])
        $array[1] += 2
    EndIf
    $counter += 1
Until $counter = 7

Share this post


Link to post
Share on other sites

cool 2 replies in like 5 minutes. thanks.

Share this post


Link to post
Share on other sites

I solved my problem and this is how it works.

$counter = 0
Dim $array[3] = ["first","second","third"]

Do 
    msgbox(1,"Hello","This should be the " & $array[$counter] & " message")
    $counter = $counter+1
    Until $counter = 3

If i make the array contain more variables then this code could count messages all day and it works for my situation thanks guys for the comments.

Share this post


Link to post
Share on other sites

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  
Followers 0