changeset 10:0374ae06729e

Start playing around with loop block definitions
author IBBoard <dev@ibboard.co.uk>
date Mon, 02 Jan 2017 21:01:39 +0000
parents 19fd9fd373d7
children e0a92558400f
files 1-Ruby/blocks-irb.output 1-Ruby/blocks-ruby.output 1-Ruby/blocks.rb
diffstat 3 files changed, 60 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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> 
--- /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
--- /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