MC logo

While Loop

  Ruby Example Code

<<Conditional II wh1.rb For Loop>>
# Some counting with a while.
a = 0
while a < 15
    print a, " "
    if a == 10 then
        print "made it to ten!!"
    end
    a = a + 1
end
print "\n"

# Here's a way to empty an array.
joe = [ 'eggs.', 'some', 'break', 'to', 'Have' ]
print(joe.pop, " ") while joe.size > 0
print "\n"
See:Ruby User's GuideRuby Manual

The while loop is conventional, but it also has a postfix form.
<<Conditional II For Loop>>