diff --git a/helpers.php b/helpers.php
index <HASH>..<HASH> 100755
--- a/helpers.php
+++ b/helpers.php
@@ -384,20 +384,18 @@ if (! function_exists('retry')) {
     function retry($times, callable $callback, $sleep = 0, $when = null)
     {
         $attempts = 0;
-        $times--;
 
         beginning:
         $attempts++;
+        $times--;
 
         try {
             return $callback($attempts);
         } catch (Exception $e) {
-            if (! $times || ($when && ! $when($e))) {
+            if ($times < 1 || ($when && ! $when($e))) {
                 throw $e;
             }
 
-            $times--;
-
             if ($sleep) {
                 usleep($sleep * 1000);
             }
Improve function `retry()` (#<I>)

If given a value less than 1 for `$times`, function could be stuck in an infinite loop.