Unless in control flow in ruby


UNLESS in ruby control flow

these are the instructions.

                  * We've started you off in the editor. Replace the ___s with the correct unless statement code so your program prints out "I'm writing Ruby programs!"

this is the error message

                      * (ruby):2: syntax error, unexpected tSTRING_BEG, expecting keyword_then or ';' or '\n'

if false "I'm writing ruby programs!"

Replace this line with your code.


can we see your code, please?


this is what I typed:
hungry = false
if false "I'm writing ruby programs!"
print "I'm writing ruby programs!"
unless hungry
print "time to eat!"


you need to get rid of "I'm writing ruby programs!" on line two, tell me if this fixes anything


did not fix it just said
(ruby):6: syntax error, unexpected $end, expecting keyword_end


can I have the link to this exercise?



You have your syntax backwards, it needs to look like:

hungry = false

unless hungry
  puts "I'm writing Ruby programs!"
  puts "Time to eat!"


thanks that worked!!!! :grinning:


make sure that you look at the example and the information it gives you. Also, you needed to use puts instead of print.
glad you passed though


Something to note:

if false

will always be false. Just because it IS false, does not mean it will be evaluated as true. It will always end up in the else pile.


you're right, I thought that for some reason it said

if hungry == false

but if it's just if false, then it's evaluating false and not the variable.
edit: the below post clarifies that it's not evaluating false, but what it actually is doing.


False cannot be evaluated. It is always false and the only way to make it true is to NOT it.

not false == true

This is how we get false to follow the true path.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.