; ======== After
Global $_Loop1_hTimer, $iState
Global $a_MyLoops[3][3] = [ [ 2 ], _
[ "Loop1", 0, 1 ], _
[ "Loop_Check", 0, 1 ] ]
While 1 ;Управляющий цикл
For $Loop = 1 To $a_MyLoops[0][0] Step 1
If $a_MyLoops[$Loop][2] Then ;State=Resume
Switch Call( $a_MyLoops[$Loop][0], $a_MyLoops[$Loop][1] )
Case -1 ;Internal stop
$a_MyLoops[$Loop][1] = 0
ContinueCase
Case -2 ;Internal pause
$a_MyLoops[$Loop][2] = 0
Case N ;<Any special internal code
EndSwitch
EndIf
Next
WEnd
Func Loop1( ByRef $__idx )
Switch $__idx
Case 0
ConsoleWrite( "С вероятностью 0.2 цикл прекратит работу" & @CRLF)
If Not $_Loop1_hTimer Or TimerDiff( $_Loop1_hTimer ) > 1000 Then
$_Loop1_hTimer = TimerInit()
$iState = ( Random( 1, 5, 1 ) = 4
EndIf
Case 1
ConsoleWrite( "Цикл будет остановлен ДО выполнения этой части" & @CRLF)
Sleep( 10 )
Case Else
$__idx = -1 ;Restart Loop1
EndSwitch
; ---
$__idx += 1
Return 0
EndFunc
Func Loop_Check( ByRef $__idx )
Switch $__idx
Case 0
If $iState Then
If $iState = 2 Then
$a_MyLoops[1][2] = 0 ;External Loop1 stop!
EndFunc
; -
$iState = 0
EndIf
Case Else
$__idx = -1 ;Restart Loop_Check
EndSwitch
; ---
$__idx += 1
Return 0
EndFunc