Jump to content

Recommended Posts

Posted

I have been trying to move around the values etc, but nothing seems to be working. In this case $i goes up to 18, but I want it to go up to $vLoop1 * $vLoop2 which is 10. Thank you.

Global $vLoop1, $vLoop2, $i

While $vLoop2 <= 2
$vLoop1 = 0
$vLoop2 += 1
While $vLoop1 <= 5

$i += 1
MsgBox(0, "", $i)

$vLoop1 += 1
WEnd
WEnd

 

Posted

Uninititalised counters will start at 0, not 1. Better explicitly define what you want your loops to do.:)

Global $i=0
For $vLoop2=1 to 2 Step 1
    For $vLoop1=1 to 5 Step 1
        $i+=1
        MsgBox(0,"",$i)
    Next
Next

 

Posted
8 minutes ago, RTFC said:

Uninititalised counters will start at 0, not 1. Better explicitly define what you want your loops to do.:)

Global $i=0
For $vLoop2=1 to 2 Step 1
    For $vLoop1=1 to 5 Step 1
        $i+=1
        MsgBox(0,"",$i)
    Next
Next

 

I did something similar first, and it worked, but then I ran into problems exiting the loop, ie. if $vLoop1 value changes because of given arguments. How would I rewrite this to use While loop instead?

Posted

For loops are much better imho, not sure what you mean by "I ran into problems exiting the loop", however to do the same using While Wend you could use the following:

Global $vLoop1 = 1, $vLoop2 = 1, $i = 0

While $vLoop2 <= 2
    $vLoop2 += 1
    While $vLoop1 <= 5
        $i += 1
        ConsoleWrite($i & @CRLF)
        $vLoop1 += 1
    WEnd
    $vLoop1 = 1
WEnd

 

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
  • Recently Browsing   0 members

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