# ++ Help

**URL:** <https://www.ruby-forum.com/t/help/114220>\
**Category:** Ruby\
**Created:** [September 10, 2007, 5:51am UTC](https://www.ruby-forum.com/t/help/114220 "2007-09-10T05:51:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmcdougall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/74df32/32.png) [@lmcdougall](https://www.ruby-forum.com/u/lmcdougall)\
**Post date:** [September 10, 2007, 5:51am UTC](https://www.ruby-forum.com/t/help/114220/1 "2007-09-10T05:51:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lmcdougall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/74df32/32.png) [@lmcdougall](https://www.ruby-forum.com/u/lmcdougall)\
**Post date:** [September 10, 2007, 5:58am UTC](https://www.ruby-forum.com/t/help/114220/2 "2007-09-10T05:58:50Z")

</div>

On 9/9/07, Luis E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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)

---

<div class="post-metadata">

**Author:** ![lmcdougall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/74df32/32.png) [@lmcdougall](https://www.ruby-forum.com/u/lmcdougall)\
**Post date:** [September 10, 2007, 11:28am UTC](https://www.ruby-forum.com/t/help/114220/3 "2007-09-10T11:28:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lmcdougall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/74df32/32.png) [@lmcdougall](https://www.ruby-forum.com/u/lmcdougall)\
**Post date:** [September 11, 2007, 12:32am UTC](https://www.ruby-forum.com/t/help/114220/4 "2007-09-11T00:32:44Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![lmcdougall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/74df32/32.png) [@lmcdougall](https://www.ruby-forum.com/u/lmcdougall)\
**Post date:** [September 11, 2007, 12:44am UTC](https://www.ruby-forum.com/t/help/114220/5 "2007-09-11T00:44:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lmcdougall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/74df32/32.png) [@lmcdougall](https://www.ruby-forum.com/u/lmcdougall)\
**Post date:** [September 11, 2007, 12:48am UTC](https://www.ruby-forum.com/t/help/114220/6 "2007-09-11T00:48:57Z")

</div>

On 9/10/07, Jeremy W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
