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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top