Sign in to follow this  
Followers 0
fielmann

Creating a dynamic number of loops

4 posts in this topic

#1 ·  Posted (edited)

Hello autoit friends,

howto create a dynamic number of loops? :)

It should like like (e.g. for a number of 3 loops):

;~~~~~~~~~~~~~~~~~~

For $loop1 = 1 to 10

For $loop2 = 1 to 10

For $loop3 = 1 to 10

; do something

next

next

next

;~~~~~~~~~~~~~~~~~~

But how to make it DYNAMIC ?

Any ideas? ;)

Carsten

Edited by fielmann

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

is this what you want?

$min=Random(1,10,1)
$max=Random(10,100,1)

For $i=$min to $max
;do stuff
Next

if not then try to explain better what you want..

Edited by alexmadman

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hello autoit friends,

howto create a dynamic number of loops? :)

It should like like (e.g. for a number of 3 loops):

;~~~~~~~~~~~~~~~~~~

For $loop1 = 1 to 10

For $loop2 = 1 to 10

For $loop3 = 1 to 10

; do something

next

next

next

;~~~~~~~~~~~~~~~~~~

But how to make it DYNAMIC ?

Any ideas? ;)

Carsten

You need some sort of recursive function. Here is a simple example

Dim $a[4] = [3,4,5,2];the upper count for each loop
Dim $r[4]
Global $x=0
startloop($a,0)

Func startloop($b,$c)
Local $n
If $c < UBound($b) Then
        For $n = 1 To $b[$c]
            $r[$c] = $n
            Startloop($b,$c + 1)
        Next
    Else
        Dosomething()
    EndIf
EndFunc
Func Dosomething()
    $x += 1
    ConsoleWrite("loop vals are ")
    For $p = 1 To UBound($a)
      ConsoleWrite($r[$p - 1] & ', ')
    Next
    ConsoleWrite( "count = " & $x & @CRLF)
EndFunc

BTW, welcome to the forums; an interesting first question. :D

EDIT: improved example a bit

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

You need some sort of recursive function. Here is a simple example

[...]

BTW, welcome to the forums; an interesting first question. :D

EDIT: improved example a bit

Hello Martin!

thx 4 reply an the example with the recursive function.

that was exactly what I'm seraching for

thx also 4 your pleasent welcome! :)

I work several years with autoit 2 + 3, but I never realized this forum. ;)

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