diff --git a/src/debugger/debugger.ml b/src/debugger/debugger.ml
index a1a1aaab311b4e3e8b45204f2fb933d6f34c291f..7f75b176ecf945dc43933b068ad087c6582b80b3 100644
--- a/src/debugger/debugger.ml
+++ b/src/debugger/debugger.ml
@@ -43,20 +43,22 @@ let printStatus () =
     print_endline (CM.queuePrettyStatus ());
     printResult ()
 
-let rec repeat (n:int) (action: unit -> unit) =
+(** Repeat either n times or until action returns true *)
+let rec repeat (n:int) (action: unit -> bool) =
     if n <= 0
     then ()
-    else (action() ; repeat (n-1) action)
+    else (if action() then () else repeat (n-1) action)
 
 let doStep args =
     let action() =
         if Reasoner.reasonerFinished ()
-        then print_endline "Reasoner already finished!"
+        then (print_endline "Reasoner already finished!"; true)
         else
           try
             Reasoner.runReasonerStep ();
-            if (Reasoner.reasonerFinished ()) then printResult();
-          with CoAlgMisc.CoAlg_finished _ -> printResult()
+            if (Reasoner.reasonerFinished ()) then (printResult(); true)
+            else false
+          with CoAlgMisc.CoAlg_finished _ -> (printResult(); true)
     in
     let steps = match args with
                 | (str::_) -> (int_of_string str)