view 1-Ruby/blocks-irb.output @ 16:8d46064c9afc

Be a nice Ruby user and follow block convention for do/end vs {}
author IBBoard <dev@ibboard.co.uk>
date Tue, 03 Jan 2017 20:38:45 +0000
parents 0374ae06729e
children
line wrap: on
line source

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>