我正在尝试以特定的顺序运行不同的X次函数。
Global $Runner
HotKeySet("{F8}", "start")
HotKeySet("{F9}", "stop")
While 1
Sleep(100)
WEnd
Func start()
Local $1 = 0
Local $2 = 1
Local $3 = 44
$Runner = Not $Runner
While $Runner
If $1 <= $2 Then
<rune some code>
<$1 = $1 + 1>
ElseIf $1 >= $2 Then
<run some other code>
<$1 = 0> ; To star the loop again
Until $1 has run 44 times Then
<last piece of code>
EndIf
WEnd
EndFunc ;==>start
Func stop()
Exit
EndFunc ;==>stop
我宣布了三个变量:
$1 = 0
$2 = 1
$3 = 44
我试图以下列方式运行它:
If $1 <= $3 Then
<rune some code>
Else $1 >= $3 Then
<run some other code>
;then repeat from start
Until $1 has run 44 times Then
<last piece of code>
我不知道如何在第一个代码完成44个循环后运行第三个代码。关于如何尽可能轻松地做到这一点的任何提示?订单应该是:
答案 0 :(得分:0)
$flag = 1
For $i = 1 To 44
If $i = 44 Then ;every 44th time
MsgBox(0, $i , 'run $3') ;do thing 3
$i = 0 ;reset the loop we are counting to 44 with
ContinueLoop
EndIf
If $flag = 3 Then ;every third time
MsgBox(0, $i , 'run $2') ;do thing 2
$flag = 1 ;reset the flag we are counting to 3 with
ContinueLoop
EndIf
If $flag < 3 Then ;every first and second time
MsgBox(0, $i , 'run $1') ;do thing 1
$flag += 1 ;iterate the flag we are counting to 3 with
ContinueLoop
EndIf
Next
答案 1 :(得分:0)
......我怎么能尽可能轻松地做到这一点?
根据Documentation - Language Reference - Loop Statements:
循环是指您重复多次的脚本部分的方式。您可能希望循环给定次数,或者您可能希望重复一段脚本,只要某个条件为真或假。
示例:
While True
For $i1 = 1 To 44
For $i2 = 1 To 2
ConsoleWrite($i1 & ' function1' & @CRLF)
Next
ConsoleWrite($i1 & ' function2' & @CRLF)
Next
ConsoleWrite($i1 & ' function3' & @CRLF)
WEnd
无限重复:
1 function1
1 function1
1 function2
...
44 function1
44 function1
44 function2
45 function3
预定命令的解释留有解释空间;任何意图很容易实现移动循环或函数调用上一层或下一层。