Skip to content

Instantly share code, notes, and snippets.

@stevencombs
Created October 25, 2013 22:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save stevencombs/7162634 to your computer and use it in GitHub Desktop.
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