[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Luis Enrique

9/10/2007 3:52:00 AM

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-....

4 Answers

Wilson Bilkovich

9/10/2007 3:58:00 AM

0

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

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)

Bertram Scharpf

9/10/2007 9:27:00 AM

0


Hi,

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



--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...

Jeremy Woertink

9/10/2007 10:33:00 PM

0


> 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-....

Chris Worrall

9/10/2007 10:44:00 PM

0

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-....
>
>