# HG changeset patch # User IBBoard # Date 1483391795 0 # Node ID e5b84cc7bc29b66849566e369dde6897014244a9 # Parent e0a92558400fe53d0882bcd119995943141564f3 Update logic script re: "then" in "if else" statements diff -r e0a92558400f -r e5b84cc7bc29 1-Ruby/logic-irb.output --- 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 diff -r e0a92558400f -r e5b84cc7bc29 1-Ruby/logic-ruby.output --- 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 diff -r e0a92558400f -r e5b84cc7bc29 1-Ruby/logic.rb --- 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