2017-12-09 5 views
0

異なる関数Xを特定の順序で実行しようとしています。異なる関数を特定の順序で実行する

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> 

私は第3のコードの実行を作成する方法がわからない:私はその方法でそれを実行しようとしている

$1 = 0 
$2 = 1 
$3 = 44 

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 

は、私は三つの変数を宣言しました最初の44回のループを終えた後。私がこれをできるだけ簡単にやり遂げる方法についてのヒント?順序は:

  • [最初のコード]は常に2回実行する必要があります。
  • [第1コード]が2回ループした後、常にループごとに実行します。
  • [第3コード]は最初のコードが44回ループした後に常に実行します。
+1

for $ i = 1〜44 next' – matrix

答えて

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 
0

&hellip;私はこれをできるだけ簡単にやり遂げることができますか? Documentation - Language Reference - Loop Statementsを1として

ループは、あなたが何回も繰り返して、スクリプトのセクションを参照してください方法です。特定の条件が真または偽である限り、指定した回数だけループするか、またはスクリプトのセクションを繰り返すことができます。

例:

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 

説明は解釈の余地が。どのような意図であれ、ループやファンクションコールをレベルアップまたはダウンすることで容易に達成できます。

関連する問題