Script Monitor icon Script Monitor — Monitor and diagnose running ARC scripts: view active script labels, statuses, and stop long-running or background scripts easily. Try it →
Asked — Edited
Script Control - Looping Functionality Question. A Bug Or Brain Fart?

Script Control - Looping Functionality Question. A Bug Or Brain Fart?

Situation: I've looked over all the scripts in the cloud and haven't seemed to find anything pertaining to looping. So I wanted to write a short tutorial for the community. So the simple loop example went okay, but as I wrote a loop within a loop. I am finding myself a little confused as the the process flow of the following code...

Here is the script:


#Loop With In Loop
Print("Loop with a loop")
$OuterCounter = 3
$InnerCounter = 2

:OuterLoopStep
  If ($OuterCounter >= 0)
    #Execute Outer Loop Command
    Print(">Outer Loop Value: $OuterCounter)
    $OuterCounter = $OuterCounter - 1

    :InnerLoopStep
      If ($InnerCounter >= 0)
        #Execute Inner Loop Command
        Print("Inner Loop Value: $InnerCounter")
        $InnerCounter = $InnerCounter - 1
        Goto (InnerLoopStep)
      Else 
        Sleep(3000)
        Goto(OuterLoopStep)
        #Wanted to use EndIf for formality, but not nessecary
  Else
    Print("Finished")
  EndIf

Here is the output of the debugger: Start 2: Print("Loop with a loop") Loop with a loop 3: $OuterCounter = 3 4: $InnerCounter = 2 6: :OuterLoopStep 7: If ($OuterCounter >= 0) 9: Print(">Outer Loop Value: $OuterCounter)

Outer Loop Value: 3 10: $OuterCounter = $OuterCounter - 1 12: :InnerLoopStep 13: If ($InnerCounter >= 0) 15: Print("Inner Loop Value: $InnerCounter") Inner Loop Value: 2 16: $InnerCounter = $InnerCounter - 1 17: Goto (InnerLoopStep) 13: If ($InnerCounter >= 0) 15: Print("Inner Loop Value: $InnerCounter") Inner Loop Value: 1 16: $InnerCounter = $InnerCounter - 1 17: Goto (InnerLoopStep) 13: If ($InnerCounter >= 0) 15: Print("Inner Loop Value: $InnerCounter") Inner Loop Value: 0 16: $InnerCounter = $InnerCounter - 1 17: Goto (InnerLoopStep) 13: If ($InnerCounter >= 0) 18: Else 19: Sleep(3000) 20: Goto(OuterLoopStep) 7: If ($OuterCounter >= 0) 9: Print(">Outer Loop Value: $OuterCounter) Outer Loop Value: 2 10: $OuterCounter = $OuterCounter - 1 12: :InnerLoopStep 13: If ($InnerCounter >= 0) 18: Else 19: Sleep(3000) 20: Goto(OuterLoopStep) 7: If ($OuterCounter >= 0) 9: Print(">Outer Loop Value: $OuterCounter) Outer Loop Value: 1 10: $OuterCounter = $OuterCounter - 1 12: :InnerLoopStep 13: If ($InnerCounter >= 0) 18: Else 19: Sleep(3000) 20: Goto(OuterLoopStep) 7: If ($OuterCounter >= 0) 9: Print(">Outer Loop Value: $OuterCounter) >Outer Loop Value: 0 10: $OuterCounter = $OuterCounter - 1 12: :InnerLoopStep 13: If ($InnerCounter >= 0) 18: Else 19: Sleep(3000) 20: Goto(OuterLoopStep) Here's where my confusion starts. Any ideas? Am I missing something obvious? 7: If ($OuterCounter >= 0) 10: $OuterCounter = $OuterCounter - 1 12: :InnerLoopStep 13: If ($InnerCounter >= 0) 18: Else 19: Sleep(3000) 20: Goto(OuterLoopStep) 7: If ($OuterCounter >= 0) 10: $OuterCounter = $OuterCounter - 1 12: :InnerLoopStep 13: If ($InnerCounter >= 0) 18: Else 19: Sleep(3000) 20: Goto(OuterLoopStep) 7: If ($OuterCounter >= 0) 10: $OuterCounter = $OuterCounter - 1 12: :InnerLoopStep 13: If ($InnerCounter >= 0) 18: Else 19: Sleep(3000) 20: Goto(OuterLoopStep)

and on and on the loop executes...


ARC Pro

Upgrade to ARC Pro

Stay on the cutting edge of robotics with ARC Pro, guaranteeing that your robot is always ahead of the game.

#17  

Wow, that will be better then a lazier light show at a Pink Floyd concert!

Author Avatar
PRO
Synthiam
LinkedIn Thingiverse Twitter YouTube GitHub
#18  

Compiler's condition tree fixed - sorry for the delay:)


# Loop With In Loop
Print("Loop with a loop")
$OuterCounter = 3
$InnerCounter = 2

:OuterLoopStep

IF ($OuterCounter >= 0)
  
  Print("Outer Loop Value: $OuterCounter)
  $OuterCounter--
  
  :InnerLoopStep
  
  IF ($InnerCounter >= 0)
    Print("Inner Loop Value: $InnerCounter")
    $InnerCounter--
    Goto (InnerLoopStep)
  ELSE 
    Sleep(1000)
    Goto(OuterLoopStep)
  ENDIF 
    
ELSE 
  
  Print("Finished")
  
ENDIF 

User-inserted image