Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > genie.rb:20: syntax error, unexpected $end, expecting kEND

Reply
Thread Tools

genie.rb:20: syntax error, unexpected $end, expecting kEND

 
 
Alec Williams
Guest
Posts: n/a
 
      07-19-2009
I get "genie.rb:20: syntax error, unexpected $end, expecting kEND" every
I try to run the above program. It's just something I did for fun to
impress freinds/family. I've looked over it many times, trying to mess
with things a little to fix it, but nothing seems to work. I'm pretty
new to the whole programming scene (I actually started yesterday) so I
probably missed something really easy but it still baffels me. Help
would be greatly appreciated for anyone who would be kind enough to give
it.

Attachments:
http://www.ruby-forum.com/attachment/3884/genie.rb

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
David A. Black
Guest
Posts: n/a
 
      07-19-2009
Hi --

On Sun, 19 Jul 2009, Alec Williams wrote:

> I get "genie.rb:20: syntax error, unexpected $end, expecting kEND" every
> I try to run the above program. It's just something I did for fun to
> impress freinds/family. I've looked over it many times, trying to mess
> with things a little to fix it, but nothing seems to work. I'm pretty
> new to the whole programming scene (I actually started yesterday) so I
> probably missed something really easy but it still baffels me. Help
> would be greatly appreciated for anyone who would be kind enough to give
> it.


Every if statement has to have an 'end'. Right now you've got more
if's than end's. It's because you're using this:

else
if

(with no 'end' for the if) instead of:

elsif

They're both OK, but if you use the first one, you're starting a new
if and it has to have its own end.

Compare these two:

if x
puts "x is true"
elsif y
puts "y is true"
else
puts "Neither is true"
end

if x
puts "x is true"
else
if y
puts "y is true"
else
puts "Neither is true"
end
end

You're doing something like the second, but without matching if/end.


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Now available: The Well-Grounded Rubyist (http://manning.com/black2)
Training! Intro to Ruby, with Black & Kastner, September 14-17
(More info: http://rubyurl.com/vmzN)

 
Reply With Quote
 
 
 
 
Stefano Crocco
Guest
Posts: n/a
 
      07-19-2009
On Sunday 19 July 2009, Alec Williams wrote:
> |I get "genie.rb:20: syntax error, unexpected $end, expecting kEND" every
> |I try to run the above program. It's just something I did for fun to
> |impress freinds/family. I've looked over it many times, trying to mess
> |with things a little to fix it, but nothing seems to work. I'm pretty
> |new to the whole programming scene (I actually started yesterday) so I
> |probably missed something really easy but it still baffels me. Help
> |would be greatly appreciated for anyone who would be kind enough to give
> |it.
> |
> |Attachments:
> |http://www.ruby-forum.com/attachment/3884/genie.rb


You are missing two end before the last one. By the way, if you want to have
several "branches" in your if statement, you can use the elsif keyword inst=
ead
of nested else/if. This would make your code shorter and much easier to read
and debug. Here's how it would look:

puts 'You see a lamp on the floor of a dusty room. Do you pick it up and ru=
b it?'
lamp=3Dgets.chomp

if lamp=3D=3D'No'
puts 'You turn around, and walk out of the room, always to wonder whether=
or not you should have rubbed it...'
elsif lamp=3D=3D'Yes'
puts 'You walk up to the lamp and stroke it. Suddenly a genie bursts out =
and says "You have released me from my eternal prison. I shall now grant yo=
u one wish! State it in "I wish for (blank)" format=20
please. State it, and it shall be done."'
wish=3Dgets.chomp
if (wish=3D=3D 'I wish for world peace' or wish=3D=3D 'I wish for the end=
of world hunger')
puts 'That\'s very thoughtful of you. It shall be done!'
elsif (wish=3D=3D 'I wish for the winning lottery ticket' or wish=3D=3D '=
I wish for $1,000,000')
puts 'That is very selfish of you, but I must hold a promise. Your wish=
shall be granted.'
else
puts 'Your wish is my command.'
end
end
puts 'You walk out of the dusty room, into the sunshine, awaiting a changed=
life as a result of your recently granted wish.'

I hope this helps

Stefano


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax error, unexpected '}', expecting kEND Louise Rains Ruby 4 08-11-2010 10:23 PM
rakefile gives syntax error, unexpected ':', expecting $end thufir Ruby 2 04-21-2008 03:50 AM
unexpected kEND, expecting $ Comfort Eagle Ruby 2 11-23-2006 10:32 PM
parse error, unexpected $, expecting kEND instantrails Raju Gautam Ruby 1 10-29-2006 11:31 AM
parse error, unexpected $, expecting kEND Slain Wilde Ruby 1 08-09-2006 03:34 AM



Advertisments