++ Help

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

On 9/9/07, Luis E. [email protected] wrote:

syntax error, unexpected kEND

if I take the d++ then it is ok.

how should I use the ++ or +=?

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)

Hi,

Am Montag, 10. Sep 2007, 12:57:36 +0900 schrieb Wilson B.:

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

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

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 W. [email protected] wrote:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs