From 52103c73c2bcfcbbf447900249334f9c6eda418a Mon Sep 17 00:00:00 2001 From: Will Date: Fri, 20 Apr 2018 12:30:32 -0400 Subject: [PATCH] Provide an optional starting point for loop() This adds an optional argument to the top level `loop` method, while continuing to default to `0`. --- src/kernel.cr | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/kernel.cr b/src/kernel.cr index 73e5b9d6bab7..70d4a2c3ac7e 100644 --- a/src/kernel.cr +++ b/src/kernel.cr @@ -15,7 +15,7 @@ ARGV = Array.new(ARGC_UNSAFE - 1) { |i| String.new(ARGV_UNSAFE[1 + i]) } ARGF = IO::ARGF.new(ARGV, STDIN) # Repeatedly executes the block, passing an incremental `Int32` -# that starts with `0`. +# that starts with the argument, which defaults to `0`. # # ``` # loop do |i| @@ -25,11 +25,10 @@ ARGF = IO::ARGF.new(ARGV, STDIN) # # ... # end # ``` -def loop - i = 0 +def loop(start = 0) while true - yield i - i += 1 + yield start + start += 1 end end