# HG changeset patch # User IBBoard # Date 1483390899 0 # Node ID 0374ae06729eb41874ed5d2da16d80dec2b83e8e # Parent 19fd9fd373d74c46cbdb264aa2f2434b1e3a57ca Start playing around with loop block definitions diff -r 19fd9fd373d7 -r 0374ae06729e 1-Ruby/blocks-irb.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/1-Ruby/blocks-irb.output Mon Jan 02 21:01:39 2017 +0000 @@ -0,0 +1,35 @@ +blocks.rb(main):001:0> #! /usr/bin/env ruby +blocks.rb(main):002:0* +blocks.rb(main):003:0* x = 1 +=> 1 +blocks.rb(main):004:0> +blocks.rb(main):005:0* # Inline loops +blocks.rb(main):006:0* x = x + 1 while x < 10 +=> nil +blocks.rb(main):007:0> puts x +10 +=> nil +blocks.rb(main):008:0> +blocks.rb(main):009:0* x = x - 1 until x == 1 +=> nil +blocks.rb(main):010:0> puts x +1 +=> nil +blocks.rb(main):011:0> +blocks.rb(main):012:0* # Conventional loops +blocks.rb(main):013:0* while x < 10 +blocks.rb(main):014:1> x = x + 1 +blocks.rb(main):015:1> end +=> nil +blocks.rb(main):016:0> puts x +10 +=> nil +blocks.rb(main):017:0> +blocks.rb(main):018:0* until x == 1 +blocks.rb(main):019:1> x = x - 1 +blocks.rb(main):020:1> end +=> nil +blocks.rb(main):021:0> puts xblocks.rb(main):021:0> +1 +=> nil +blocks.rb(main):021:0> diff -r 19fd9fd373d7 -r 0374ae06729e 1-Ruby/blocks-ruby.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/1-Ruby/blocks-ruby.output Mon Jan 02 21:01:39 2017 +0000 @@ -0,0 +1,4 @@ +10 +1 +10 +1 diff -r 19fd9fd373d7 -r 0374ae06729e 1-Ruby/blocks.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/1-Ruby/blocks.rb Mon Jan 02 21:01:39 2017 +0000 @@ -0,0 +1,21 @@ +#! /usr/bin/env ruby + +x = 1 + +# Inline loops +x = x + 1 while x < 10 +puts x + +x = x - 1 until x == 1 +puts x + +# Conventional loops +while x < 10 + x = x + 1 +end +puts x + +until x == 1 + x = x - 1 +end +puts x \ No newline at end of file