On 12 Aug 2011, at 14:10, amir a. wrote:

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


sum = 0
50.times {|x| sum = sum + x + gets.to_i}
puts sum


> 
> 2 - int a,b,c,d;
>    while( 1 ) {
>       cin >> a >> b >> c >>d ;
>       if( a < 0 || b < 0 )
>          break;
>       cout << a << " " << b << " " << c << " " << d << endl;
>    }
> 
> 
while true
	a, b, c, d = gets.split.map {|s| s.to_i}
	break if a < 0 || b < 0
	STDOUT << a << " " << b << " " << c << " " << d << "\n";
end



Dave.

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