Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Various examples of Ruby control flows performing the same task: printing "Hello. " 10 times.
# Ruby Getting Started with Programming
# Control flow examples
# Dr. Steven B. Combs, coding novice
# Do
puts "Do"
10.times do
print "Hello. "
end
puts ""
# Do Alternate with brackets
puts "Do with Brackets"
10.times {print "Hello. "}
puts ""
# While
c = 1
puts "While"
while c < 11
print "Hello. "
c += 1
end
puts ""
# Until
c = 1
puts "Until"
until c > 10
print "Hello. "
c += 1
end
puts ""
# Loop
puts "Loop"
c = 0
loop {
c += 1
print "Hello. "
break if c >= 10
}
puts ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.