Do..Until Question

Recommended Posts

So im trying to make aloop but  i need it so after x amount of times it will do a function, ive been using while 1,wend but i need somthing to count so

would i be able to do somthing like

```\$I = 0
Do
Code
\$I = \$1+1

Until \$I = 10 Then

Do function```

Now if that is possible if i have a exit loop inside would it do the "then" function

```\$I = 0
Do
Code
\$I = \$1+1
if
Exitloop
else
endif
Until \$I = 10 Then

Do function```

Share on other sites

Use For...To...Next

```For \$i = 1 To 10
ConsoleWrite(\$i & @CRLF)
Next```

Share on other sites
1 minute ago, czardas said:
```For \$i = 1 To 10
ConsoleWrite(\$i & @CRLF)
Next```

Use For...To...Next

So for example

```Func AA()
For \$i = 1 To 10
\$AA = _ImageSearchArea("Images/AA.png",1,\$L,\$T,\$B,\$R, \$x, \$y, 50)
If \$AA = 1 Then
MouseClick("Left",\$x,\$y)
Sleep(200)
ConsoleWrite("True" & @CRLF)
ExitLoop
EndIf
Next
Call("A")
EndFunc```

If Func AA() if false 10 times it will call 1 right?

i would want if its true to not Call("A") and just move on to lets say Func AA2()

would that mean somthing like..

```Func AA()
For \$i = 1 To 10
\$AA = _ImageSearchArea("Images/AA.png",1,\$L,\$T,\$B,\$R, \$x, \$y, 50)
If \$AA = 1 Then
MouseClick("Left",\$x,\$y)
Sleep(200)
ConsoleWrite("True" & @CRLF)
Call("AA2")
ExitLoop
EndIf
Next
Call("A")
EndFunc```

Would i still need the exit loop in there?

Share on other sites

Do some tests and see what it does for yourself.

Share on other sites

Ok and is there a way to have a Func with a count down and when the timer hits 0 it does that func

So like

1 func:20 sec left

2 func 10 sec left

3 fun 15 sec left

when 2 hits 0 it will do 2 then restart timer

ive been searching but nothing has been comming up relevent then again im pretty new still

Share on other sites

Careful ! This will run forever

```_20Sec()

Func _20Sec()

Sleep(1000*20)
MsgBox(0, "", "20 Seconds is Up")
_10Sec()

EndFunc

Func _10Sec()

Sleep(1000*10)
MsgBox(0, "", "10 Seconds is Up")
_20Sec()

EndFunc```

My Contributions...

FTP Connection Tester / INI File - Read, Write, Save & Load Example

Share on other sites
3 minutes ago, l3ill said:

Careful ! This will run forever

```_20Sec()

Func _20Sec()

Sleep(1000*20)
MsgBox(0, "", "20 Seconds is Up")
_10Sec()

EndFunc

Func _10Sec()

Sleep(1000*10)
MsgBox(0, "", "10 Seconds is Up")
_20Sec()

EndFunc```

Ok so  i would put my code like this?

```_20Sec()

Func _20Sec()
;;Code in here
Sleep(1000*20)
MsgBox(0, "", "20 Seconds is Up")
_10Sec()

EndFunc

Func _10Sec()
;;Code in here
Sleep(1000*10)
MsgBox(0, "", "10 Seconds is Up")
_30Sec()

EndFunc

Func _30Sec()
;; Code in here
Sleep(1000*30)
MsgBox(0, "", "30 Seconds is Up")
EndFunc```

But wouldent that do one command wait 20 sec then do 10s command then do 30 sec command?

what im looking for is when i start the script it does all 3 commands in a row with no wait then depends on each wait is then it will redo the command

so  start code would be 1,2,3

but then as the time goes 2 will go again first then 1 then 3

if that makes any sense at all

Share on other sites

Check out adlibregister in the help file...away from pc so cant supply example...

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 on other sites

GP,

A simple example...

```#include <date.au3>

Local \$b10, \$b20, \$b30

_10sec()
_20sec()
_30sec()

While 1

Switch True
Case \$b10
; run 10 second code
ConsoleWrite('10 sec run at ' & _Now() & @CRLF)
\$b10 = Not \$b10
Case \$b20
; run 20 second code
ConsoleWrite('20 sec run at ' & _Now() & @CRLF)
\$b20 = Not \$b20
Case \$b30
; run 30 second code
ConsoleWrite('30 sec run at ' & _Now() & @CRLF)
\$b30 = Not \$b30
EndSwitch

Sleep(100)

WEnd

; get out of adlibs asap so set switch and return

Func _10sec()
\$b10 = True
EndFunc   ;==>_10sec
Func _20sec()
\$b20 = True
EndFunc   ;==>_20sec
Func _30sec()
\$b30 = True
EndFunc   ;==>_30sec```

kylomas

Edited by kylomas
• 1

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

Create an account

Register a new account