while loop : execute code and THEN check condition


A

Adam Akhtar

Im sure this was possible in C but in ruby i couldnt find something
similiar.

I want a control structure which will execute the code first and then
check if the condition is true or not. something like

do

something

while (condition)
 
Ad

Advertisements

J

Joel VanderWerf

Adam said:
Im sure this was possible in C but in ruby i couldnt find something
similiar.

I want a control structure which will execute the code first and then
check if the condition is true or not. something like

do

something

while (condition)

begin
something
end while condition
 
H

Heesob Park

2008/9/7 Adam Akhtar said:
Im sure this was possible in C but in ruby i couldnt find something
similiar.

I want a control structure which will execute the code first and then
check if the condition is true or not. something like

do

something

while (condition)
begin
something
end while condition

Or

begin
something
end until condition

Regards,

Park Heesob
 
Ad

Advertisements

R

Robert Dober

Although
begin
...
end while condition

is the idiomatic way to do this I often write my loops as follows

loop do
...
break if/unless condition
...
end

I prefer it even more if my code can be refactored to

loop do
...
return ...
...
end

Cheers
Robert


--=20
C'est v=E9ritablement utile puisque c'est joli.

Antoine de Saint Exup=E9ry
 

Top