2012-11-26 3 views
2

레일에있는 루비는 ++ 값과 같은가? C에서++ 값 또는 값 ++ in rail (ruby)

는 X ++

그들은 (엄밀히 말하면) 같은 동작을하지 않습니다 .. 는 ++의 x는 레일

c++ code 
int x = 0; 
if(x++) cout << "value is not zero when compared" 
else cout << "value still zero when compared" 
//prints "value still zero when compared" 

x = 0; 
if(++x) cout << "value is not zero when compared" 
else cout << "value is still zero when compared" 
//prints "value is not zero when compared" 

시뮬 뭔가가 있나요 빠른 거기 ++의 X이고 작업 (작지만 빠른),하지만 그게 내가 원하는 이유는 .. 내가 인쇄하고 같은 라인에 값을 추가하고 싶습니다 ..하지만 추가하기 전에 값을 인쇄하고 싶습니다.

루비 코드

#print out the count of products processed, the current id, and the current name 
p "#{recCount++}:#{product.id} #{product.name}"; 
+1

게시물 증가가 보이지 않습니다 ([link] (http://devblog.avdi.org/2011/02/26/ruby-or-why-post-increment-is-tricky/)). . – dasblinkenlight

+0

팹 링크 :) .. 나를 슬프게하다 .. "언어 변호사"가된다 – baash05

답변

1

아니,하지 않습니다, 그러나 += 1있다.

+0

blisteringly inc.보다 천천히.. 그러나 그것이 비준 받았을 때? 인쇄하기 전에, 또는 후에? 재계 표 수가 10이고 위의 값을 + = 1로 지정하면 인쇄되는 내용은 무엇입니까? 10, 11? – baash05

+3

@daveatflow 존재하지 않는 운영자보다 천천히? – alex

+0

@daveatflow "blisteringly slower"라고 할 때 무슨 소리가나요? ??? – Pubby