February 2, 2004 Intro to Ruby Slide #13
Prev Next

Control Structures

while

     i = 0
     while i < 5
         puts i
         i = i + 1
     end

until

     i = 0
     until i >= 5
         puts i
         i = i + 1
     end

for

     for i in 1..4
         puts i
     end

if/elsif/else

     if i < 0
         puts "negative"
     elsif i == 0
         puts "0"
     else
         puts "positive"
     end


Prev Copyright © 2004 Walter C. Mankowski Next