++ Help

L

Luis Enrique

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
 
W

Wilson Bilkovich

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 +=?

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)
 
B

Bertram Scharpf

Hi,

Am Montag, 10. Sep 2007, 12:57:36 +0900 schrieb Wilson Bilkovich:
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
 
J

Jeremy Woertink

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
 
C

Chris Worrall

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,264
Messages
2,571,323
Members
48,006
Latest member
MelinaLema

Latest Threads

Top