Section 17. What is wrong with this code. "(ruby):8: syntax error, unexpected keyword_end, expecting $end"


#1

test_1 should be true

test_1 = true || 1+2==3

test_2 = should be true

test_2 = 1-2==-1 && 1-2==-1

test_3 = should be false

test_3 = !1-1==0
end

Please help me, I'm so confused.


#3

@roglemorph,
Remove the end statement
as it is only used in combination with a do or an IF statement

the do .... end is used a so-called =block= indicator
like

10.times do
    # begin of code-block 
    puts "===="
    # End of code-block 
  end

In Ruby you have a second possibility to encapsulate a code-block
by using a pair of curly-brackets-{ }
like

1.times { 
    # code-block
    puts "===="
  }

But you must keep in mind
that in some statements there is a strange behaviour
in order of precedence between a do-end and {..} block indicator......

http://stackoverflow.com/questions/5587264/do-end-vs-curly-braces-for-blocks-in-ruby
http://stackoverflow.com/questions/14418283/2-conditions-in-if-statement