Sign in to follow this  
Followers 0
AquilaChill

help with loops in loops(code inside)

18 posts in this topic

i've been running this script through my head to try to figure out what the problem is, but i'm dumbfound on this one.

Acording to all my au3 knowledge, it *should* work.

the problem is that it can't seem to get out of the first "For"

Can i not use a For inside a For? i'm shure its somthing simple that i've missed thats taunting me in my face.

Any help would be appreciated. :)

basicly the script is made to run x amount of apps (different apps) & then wait til somthing happens, its not the funcs it launches.

I've recently changed a big long list into a loop (it worked after this), then added another for loop inside it to take the filesize down more (problem here), but this problem is making me think about just adding the (partial) list back.

i will be checking this tomarow, as im quite tired now.

first poste on a question on code btw

CODE
$onnow = 4

$onnowa = $onnow

...

$num = 0

While 1

Global $num = $num + 1

For $lc = 1 To (8 / $onnow)

Global $lcc = $lc ;this is for an external count

For $lc2 = 1 To $onnow

Global $onnowb = $lc2

Global $path = Eval($lc2 & "path")

Global $exe = Eval($lc2 & "exe")

Global $i1 = Eval("acc" & $num)

Global $i2 = Eval("i2" & $num)

Global $title = Eval($lc2 & "title")

Global $i3 = Eval($lc2 & "i3")

Global $i4 = Eval($lc2 & "i4")

Call("go")

Next

If $onnowr = $onnowb Then Call("sleeper")

Next

WEnd


people are anoying, am i? ;) v2.95

Share this post


Link to post
Share on other sites



exitloop() ?


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

My guess is that call("go") never returns. Why do you use call? Rather, just use go(). The same with call("sleeper").

Share this post


Link to post
Share on other sites

What about updating the description and examples for Call, just a tad ? In my point of view it's not

really explained how Call can be useful in some ways and not needed at all in other scenarios.

Share this post


Link to post
Share on other sites

While 1
  code .....
Wend

You script doesn't break out of the While loop. It will just keep starting over after the outer For/Next completes.

/dev/null

exitloop() ?

Just an observation.

eltorro

Share this post


Link to post
Share on other sites

Just an observation.

observation of what ???


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

observation of what ???

I believe he was explaining your reply a bit more thoroughly in case he didn't understand what you meant (I didn't at first). He stated that the while loop needs to be broken and quoted your "ExitLoop()" for support. :)

P.S. /dev /null didn't that avatar used to be AzKay's?

Edited by dandymcgee

- Dan [Website]

Share this post


Link to post
Share on other sites

What about updating the description and examples for Call, just a tad ? In my point of view it's not

really explained how Call can be useful in some ways and not needed at all in other scenarios.

I don't have the helpfile available at the moment but you are probably right. In my opinion AutoIt has, as we all know, moved from a special purpose language to a entry level programming language. And as such I think there should be a entry level program tutorial in the help file. There is a quite good one floating around as a pdf version? Maybe we should ask the author if he would volunteer his work?

Share this post


Link to post
Share on other sites

P.S. /dev /null didn't that avatar used to be AzKay's?

Erm... nope!


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

This observation,

You script doesn't break out of the While loop. It will just keep starting over after the outer For/Next completes.

eltorro

Edited by eltorro

Share this post


Link to post
Share on other sites

Erm... nope!

:) LOL!!!


- Dan [Website]

Share this post


Link to post
Share on other sites

While 1
  code .....
Wend
oÝ÷ Ù.±Êâ¦×hzÉ÷öÖëy©(ºÚ¶)^)"Ü"Xî²Ùz-j»b
/z¶µêíê.µêÅ¢¿Í{¢jez׬&ë-jz±êïjبém¢ºèþ«¨µâ-²Ë©¦vÚ'z÷«ëhºÚ¶)^)קvËaz·°Ømë%yê^­û§q§íz¹h¢§î·«¡ûbë.²æ¥Ê+e¢l¶¬yÊ'tZ+ãazx¶Ê.¶Ú-çâ®ËE¢·hx-ërÝÚaz¾1¶§q©ex,ç©z»h~)â²­º§ë,¶«zj+zØb"Ø^¢Ø^¯Mú[Ú®Ëazx­v¬¶¬jYh½êÚ¨§Â+av'ßz·§¶ö«²ãºËpj+l~ì¢kax"Þ¡ûaz趦²Ø^ìb¶È·ö÷zW¢½ëajܨ¹Æ§ßÛn±æ¢¸§²'^hZ+jÁh¯Mú

going to check & see if changing the second For into a Do...Until will work. (first just seemed more complicated to change)

Results: success! replacing the second For with a Do..Until (after some trial & error) works.

the helpfile should explain more things about the loop functions, like which can be put inside itself, or somthing, or maybe i'm missing somthing.

now all thats left is this question i have.

the helpfile refers to "nested statements" and nothing in there says anything about it, somthing you guys could clarify?


people are anoying, am i? ;) v2.95

Share this post


Link to post
Share on other sites

As this check shows there is nothing wrong with nested for loops

testLoops()
Exit
func testLoops()
   Local $l, $i, $j = 4
   while $l <= 2
      For $i = 0 to 8/$j
         For $j = 0 to 4
            dbg("$l:=" & $l & ", $i:=" & $i & ", $j:=" & $j)
         Next
      Next
      $l +=1
   Wend
EndFunc
Func dbg($msg, $erl=@ScriptLineNumber, $err=@error, $ext=@extended)
   ConsoleWrite("(" & $erl & ") := (" & $err & ")(" & $ext & "): " & $msg & @LF)
   If $err <> 0 OR $ext <> 0 Then Return SetError($err,$ext, 0)
   Return 1
EndFunc

My output:

CODE
+>AU3Check ended.rc:0

>Running:(3.2.2.0):..\autoit-v3.2.2.0\autoit3.exe "\Code\autoit\au3\foo.au3"

(26) := (0)(0): $l:=, $i:=0, $j:=0

(26) := (0)(0): $l:=, $i:=0, $j:=1

(26) := (0)(0): $l:=, $i:=0, $j:=2

(26) := (0)(0): $l:=, $i:=0, $j:=3

(26) := (0)(0): $l:=, $i:=0, $j:=4

(26) := (0)(0): $l:=, $i:=1, $j:=0

(26) := (0)(0): $l:=, $i:=1, $j:=1

(26) := (0)(0): $l:=, $i:=1, $j:=2

(26) := (0)(0): $l:=, $i:=1, $j:=3

(26) := (0)(0): $l:=, $i:=1, $j:=4

(26) := (0)(0): $l:=, $i:=2, $j:=0

(26) := (0)(0): $l:=, $i:=2, $j:=1

(26) := (0)(0): $l:=, $i:=2, $j:=2

(26) := (0)(0): $l:=, $i:=2, $j:=3

(26) := (0)(0): $l:=, $i:=2, $j:=4

(26) := (0)(0): $l:=1, $i:=0, $j:=0

(26) := (0)(0): $l:=1, $i:=0, $j:=1

(26) := (0)(0): $l:=1, $i:=0, $j:=2

(26) := (0)(0): $l:=1, $i:=0, $j:=3

(26) := (0)(0): $l:=1, $i:=0, $j:=4

(26) := (0)(0): $l:=1, $i:=1, $j:=0

(26) := (0)(0): $l:=1, $i:=1, $j:=1

(26) := (0)(0): $l:=1, $i:=1, $j:=2

(26) := (0)(0): $l:=1, $i:=1, $j:=3

(26) := (0)(0): $l:=1, $i:=1, $j:=4

(26) := (0)(0): $l:=2, $i:=0, $j:=0

(26) := (0)(0): $l:=2, $i:=0, $j:=1

(26) := (0)(0): $l:=2, $i:=0, $j:=2

(26) := (0)(0): $l:=2, $i:=0, $j:=3

(26) := (0)(0): $l:=2, $i:=0, $j:=4

(26) := (0)(0): $l:=2, $i:=1, $j:=0

(26) := (0)(0): $l:=2, $i:=1, $j:=1

(26) := (0)(0): $l:=2, $i:=1, $j:=2

(26) := (0)(0): $l:=2, $i:=1, $j:=3

(26) := (0)(0): $l:=2, $i:=1, $j:=4

+>AutoIT3.exe ended.rc:0

>Exit code: 0 Time: 3.503

So I think we have to take another look at your initial code.

Ex: You do get a race condition if $j is 0 or nothing.

Share this post


Link to post
Share on other sites

As this check shows there is nothing wrong with nested for loops

testLoops()
Exit
func testLoops()
   Local $l, $i, $j = 4
   while $l <= 2
      For $i = 0 to 8/$j
         For $j = 0 to 4
            dbg("$l:=" & $l & ", $i:=" & $i & ", $j:=" & $j)
         Next
      Next
      $l +=1
   Wend
EndFunc
Func dbg($msg, $erl=@ScriptLineNumber, $err=@error, $ext=@extended)
   ConsoleWrite("(" & $erl & ") := (" & $err & ")(" & $ext & "): " & $msg & @LF)
   If $err <> 0 OR $ext <> 0 Then Return SetError($err,$ext, 0)
   Return 1
EndFunc

My output:

CODE
+>AU3Check ended.rc:0

>Running:(3.2.2.0):..\autoit-v3.2.2.0\autoit3.exe "\Code\autoit\au3\foo.au3"

(26) := (0)(0): $l:=, $i:=0, $j:=0

(26) := (0)(0): $l:=, $i:=0, $j:=1

(26) := (0)(0): $l:=, $i:=0, $j:=2

(26) := (0)(0): $l:=, $i:=0, $j:=3

(26) := (0)(0): $l:=, $i:=0, $j:=4

(26) := (0)(0): $l:=, $i:=1, $j:=0

(26) := (0)(0): $l:=, $i:=1, $j:=1

(26) := (0)(0): $l:=, $i:=1, $j:=2

(26) := (0)(0): $l:=, $i:=1, $j:=3

(26) := (0)(0): $l:=, $i:=1, $j:=4

(26) := (0)(0): $l:=, $i:=2, $j:=0

(26) := (0)(0): $l:=, $i:=2, $j:=1

(26) := (0)(0): $l:=, $i:=2, $j:=2

(26) := (0)(0): $l:=, $i:=2, $j:=3

(26) := (0)(0): $l:=, $i:=2, $j:=4

(26) := (0)(0): $l:=1, $i:=0, $j:=0

(26) := (0)(0): $l:=1, $i:=0, $j:=1

(26) := (0)(0): $l:=1, $i:=0, $j:=2

(26) := (0)(0): $l:=1, $i:=0, $j:=3

(26) := (0)(0): $l:=1, $i:=0, $j:=4

(26) := (0)(0): $l:=1, $i:=1, $j:=0

(26) := (0)(0): $l:=1, $i:=1, $j:=1

(26) := (0)(0): $l:=1, $i:=1, $j:=2

(26) := (0)(0): $l:=1, $i:=1, $j:=3

(26) := (0)(0): $l:=1, $i:=1, $j:=4

(26) := (0)(0): $l:=2, $i:=0, $j:=0

(26) := (0)(0): $l:=2, $i:=0, $j:=1

(26) := (0)(0): $l:=2, $i:=0, $j:=2

(26) := (0)(0): $l:=2, $i:=0, $j:=3

(26) := (0)(0): $l:=2, $i:=0, $j:=4

(26) := (0)(0): $l:=2, $i:=1, $j:=0

(26) := (0)(0): $l:=2, $i:=1, $j:=1

(26) := (0)(0): $l:=2, $i:=1, $j:=2

(26) := (0)(0): $l:=2, $i:=1, $j:=3

(26) := (0)(0): $l:=2, $i:=1, $j:=4

+>AutoIT3.exe ended.rc:0

>Exit code: 0 Time: 3.503

So I think we have to take another look at your initial code.

Ex: You do get a race condition if $j is 0 or nothing.

truthfully, near 2/5 of what you got there is out of my league/understanding, i'm a basic coder, as im shure you notice by my code (or atleast of what i showed)

i don't know what nested means, that was my question.

so your saying that i should have been able to have a For inside a For?

correct me if im wrong... as my autoit skill is nothing compared to yours (to my understanding)


people are anoying, am i? ;) v2.95

Share this post


Link to post
Share on other sites

i've been running this script through my head to try to figure out what the problem is, but i'm dumbfound on this one.

Acording to all my au3 knowledge, it *should* work.

Your own code works to.

Unless you do something in go or sleeper

Func testLoopsOP()
    ;NOTE: Missed declarations
    Global $onnowr
    Global $onnow = 4
    $onnowa = $onnow
    $num = 0
    Local $c
    While $c < 10 ;Replaced 1 to make the test stop at some point
        $c += 1
        ; Normally you should use Local as mutch as possible and declare your 
        ; variables at the top. atleast outside the loop. Autoit is forgiving in this 
        ; but we never know.
        Global $num = $num + 1
        For $lc = 1 To (8 / $onnow)
            Global $lcc = $lc  ;this is for an external count
            For $lc2 = 1 To $onnow
                
                Global $onnowb = $lc2
                Global $path = Eval($lc2 & "path")
                Global $exe = Eval($lc2 & "exe")
                Global $i1 = Eval("acc" & $num)
                Global $i2 = Eval("i2" & $num)
                Global $title = Eval($lc2 & "title")
                Global $i3 = Eval($lc2 & "i3")
                Global $i4 = Eval($lc2 & "i4")
                
                Call("go")
                
                dbg("$onnowa:=" & $onnowa & ", $lc:=" & $lc & ", $lc2:=" & $lc2 & ", $lcc:=" & $lcc & ", $num:=" & $num & "$onnow:=" & $onnow)
            Next
            If $onnowr = $onnowb Then Call("sleeper")
        Next
        $num += 1
    WEnd
EndFunc   ;==>testLoopsOP
Func sleeper()
    dbg("CALLED sleeper")
EndFunc   ;==>sleeper
Func go()
    dbg("CALLED go")
EndFunc   ;==>go

Share this post


Link to post
Share on other sites

My first sample is your code broken down to simple variables. And as you can see from my previous post your code works to.

Yes you can have as many (probably not but many) for loops inside for loops as you want...:)

The rest of my code is just for debuging (the output from my run is in the codebox). Study the dbg function you will get to love it.

Share this post


Link to post
Share on other sites

Forgot to mention that you should read the comments I made in your code about declaring variables inside a loop. Generally not cosidered to be good practice in any language.

Share this post


Link to post
Share on other sites

I don't have the helpfile available at the moment but you are probably right. In my opinion AutoIt has, as we all know, moved from a special purpose language to a entry level programming language. And as such I think there should be a entry level program tutorial in the help file. There is a quite good one floating around as a pdf version? Maybe we should ask the author if he would volunteer his work?

I have a link to it in my "Volly's links" page. Also, remember there is a online version of the helpfile if you need it.

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