changeset 12:e5b84cc7bc29

Update logic script re: "then" in "if else" statements
author IBBoard <dev@ibboard.co.uk>
date Mon, 02 Jan 2017 21:16:35 +0000
parents e0a92558400f
children 3e4ea3d47880
files 1-Ruby/logic-irb.output 1-Ruby/logic-ruby.output 1-Ruby/logic.rb
diffstat 3 files changed, 42 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/1-Ruby/logic-irb.output	Mon Jan 02 21:13:00 2017 +0000
+++ b/1-Ruby/logic-irb.output	Mon Jan 02 21:16:35 2017 +0000
@@ -44,7 +44,29 @@
 logic.rb(main):031:1> 	puts "x equal 4"
 logic.rb(main):032:1> else
 logic.rb(main):033:1* 	puts "x not equals 4"
-logic.rb(main):034:1> endlogic.rb(main):034:1> 
+logic.rb(main):034:1> end
+x equal 4
+=> nil
+logic.rb(main):035:0> 
+logic.rb(main):036:0* # "then" is optional, except in single line statement
+logic.rb(main):037:0* if x == 4 then puts "x equal 4" end
+x equal 4
+=> nil
+logic.rb(main):038:0> if x == 4 then
+logic.rb(main):039:1* 	puts "x equal 4"
+logic.rb(main):040:1> end
 x equal 4
 => nil
-logic.rb(main):034:0> 
+logic.rb(main):041:0> if x == 4
+logic.rb(main):042:1> 	puts "x equal 4"
+logic.rb(main):043:1> end
+x equal 4
+=> nil
+logic.rb(main):044:0> # The following line gives:
+logic.rb(main):045:0* #   logic.rb:…: syntax error, unexpected tIDENTIFIER, expecting keyword_then or ';' or '\n'
+logic.rb(main):046:0* #   if x == 4 puts "x equal 4" end
+logic.rb(main):047:0* #
+logic.rb(main):048:0* # if x == 4 puts "x equal 4" endlogic.rb(main):048:0# 
+logic.rb(main):048:0# 
+logic.rb(main):048:0# 
+=> nil
--- a/1-Ruby/logic-ruby.output	Mon Jan 02 21:13:00 2017 +0000
+++ b/1-Ruby/logic-ruby.output	Mon Jan 02 21:16:35 2017 +0000
@@ -5,3 +5,6 @@
 x not equal 5
 x not equal 5
 x equal 4
+x equal 4
+x equal 4
+x equal 4
--- a/1-Ruby/logic.rb	Mon Jan 02 21:13:00 2017 +0000
+++ b/1-Ruby/logic.rb	Mon Jan 02 21:16:35 2017 +0000
@@ -31,4 +31,18 @@
 	puts "x equal 4"
 else
 	puts "x not equals 4"
-end
\ No newline at end of file
+end
+
+# "then" is optional, except in single line statement
+if x == 4 then puts "x equal 4" end
+if x == 4 then
+	puts "x equal 4"
+end
+if x == 4
+	puts "x equal 4"
+end
+# The following line gives:
+#   logic.rb:…: syntax error, unexpected tIDENTIFIER, expecting keyword_then or ';' or '\n'
+#   if x == 4 puts "x equal 4" end
+#
+# if x == 4 puts "x equal 4" end
\ No newline at end of file