Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #6637
| From | Gary McGath <garym@REMOVEmcgathREMOVE.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Ruby newbie newline question |
| Date | 2012-10-08 14:18 -0400 |
| Organization | Mad Scientists' Union |
| Message-ID | <k4v5ee$o1l$1@dont-email.me> (permalink) |
I'm an experienced programmer but a complete beginner at Ruby.
I've tried to find an explanation of how newlines affect Ruby syntax,
without success. Some websites claim that Ruby doesn't care about
newlines, which is clearly false.
The following code works:
if i == 1
print "one"
elsif i == 2
print "two"
end
If I put the same code all on one line, it gets an error ("unexpected
kELSIF, expecting $end"). But if I add "then"s, i.e.,
if i == 1 then print "one" elsif i == 2 then print "two" end
then it works.
Could someone explain just what newlines do in cases like these, or at
least provide some guidelines to when I need them?
--
Gary McGath http://www.mcgath.com
Back to comp.lang.ruby | Previous | Next — Next in thread | Find similar
Ruby newbie newline question Gary McGath <garym@REMOVEmcgathREMOVE.com> - 2012-10-08 14:18 -0400
Re: Ruby newbie newline question Robert Klemme <shortcutter@googlemail.com> - 2012-10-08 22:44 +0200
Re: Ruby newbie newline question Gary McGath <garym@REMOVEmcgathREMOVE.com> - 2012-10-08 17:57 -0400
Re: Ruby newbie newline question Robert Klemme <shortcutter@googlemail.com> - 2012-10-09 18:58 +0200
csiph-web