I am learning Ruby.
This is my problem.
d=0
if some == 1..90
a=1
b=4
d++
end
I get a syntax error.
syntax error, unexpected kEND
if I take the d++ then it is ok.
how should I use the ++ or +=?
Thanks
···
--
Posted via http://www.ruby-forum.com/.
Ruby does not have pre or post-increment/decrement operators.
d++ should be: d += 1
Also, this probably doesn't do what you want:
"if some == 1..90"
I suspect you want to say: if (1..90).include?(something)
···
On 9/9/07, Luis Enrique <mail41t-now@yahoo.com> wrote:
I am learning Ruby.
This is my problem.
d=0
if some == 1..90
a=1
b=4
d++
end
I get a syntax error.
syntax error, unexpected kEND
if I take the d++ then it is ok.
how should I use the ++ or +=?
Hi,
> I am learning Ruby.
> This is my problem.
> d=0
> if some == 1..90
> a=1
> b=4
> d++
> end
>
> syntax error, unexpected kEND
>
> if I take the d++ then it is ok.
Ruby does not have pre or post-increment/decrement operators.
d++ should be: d += 1
Also, this probably doesn't do what you want:
"if some == 1..90"
I suspect you want to say: if (1..90).include?(something)
Do yourself a favour and indent your code.
d = 0
if (1..90).include? d then
a = 1
b = 4
d += 1
end
There further is the === operator that is used by the case
statement. So you may say:
d = 0
if (1..90) === d then
a, b = 1, 4
d += 1
end
or even
d = 0
case d
when 1..90 then
a, b = 1, 4
d += 1
end
Bertram
···
Am Montag, 10. Sep 2007, 12:57:36 +0900 schrieb Wilson Bilkovich:
On 9/9/07, Luis Enrique <mail41t-now@yahoo.com> wrote:
--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
d = 0
if (1..90).include? d then
a = 1
b = 4
d += 1
end
Interesting, I didn't know ruby had a "then" keyword. I've only seen it
when I'm doing VB stuff.
~Jeremy
···
--
Posted via http://www.ruby-forum.com/.
I mostly only use "then" when it's a one liner, and in that case, you
can replace it with a colon.
if x.nil? : puts y end
etc.
···
On 9/10/07, Jeremy Woertink <jeremywoertink@gmail.com> wrote:
> d = 0
> if (1..90).include? d then
> a = 1
> b = 4
> d += 1
> end
Interesting, I didn't know ruby had a "then" keyword. I've only seen it
when I'm doing VB stuff.
~Jeremy
--
Posted via http://www.ruby-forum.com/.