From: Peter Hickman Date: 2001-12-19T02:09:03+09:00 Subject: [ruby-talk:28876] Re: C++ preincrement operator Paul Brannan wrote: > In Ruby, if I do this: > x++ > > then I get a syntax error. However, if I do this: > ++x > > then I do not get a syntax error. I'm guessing that Ruby parses this > as: > +(+(x)) > > which is fine, except that a seasoned C++ programmer is trained to use > the preincrement operator, and may type this by mistake. Would it be > wise to have the interpreter emit a warning for this case? I cannot > think of any good reason to ever use ++x in an expression in Ruby. > > Paul However... x = 11 puts ++x outputs 11 as does x = 11 puts --x this is not what you were expecting I suspect. Both - and + are unary prefix operators and there is probably a 'feature' in the parser that produces this behaviour. You will have to use x += 1 and x -= 1