amir a. wrote in post #1016371:
> Hi
> I am C++ programmer and in C++ I used some thing that I want
> corresponding those things in Ruby.
> please help me.
>
> 1 - In C++ , I can write this program but in Ruby I can't:
>   int i,x;
>   int sum=0;
>   for( x=0 ; x <= 50 ; x++ ) {
>       cin >> i;
>       sum = sum + ( x + i ) ;
>   }
>   cout << sum;
>

A direct translation would be:

sum = 0

for x in 0...3
  i = gets
  sum = sum + (x + i.to_i)
end

print sum


But:

1) Experienced programmers never write:
   sum = sum +...

They write:

  sum += ....

2) In ruby for() calls each(), so ruby programmers just call each() 
directly:

sum = 0

(0...3).each do |i|
  x = gets
  sum += (i + x.to_i)
end

puts sum


And there are many ways to loop in ruby:

sum = 0

3.times do |i|
  x = gets
  sum += (i + x.to_i)
end

puts sum

-- 
Posted via http://www.ruby-forum.com/.