Skip to content

Instantly share code, notes, and snippets.

@Papillard
Created July 12, 2017 08:48
Show Gist options
  • Save Papillard/0c501a5fe288f490397c0d8ecc55f10b to your computer and use it in GitHub Desktop.
Save Papillard/0c501a5fe288f490397c0d8ecc55f10b to your computer and use it in GitHub Desktop.
Basic loops with while and for
# While loop example
price = rand(1..5)
choice = nil
while choice != price
puts "What's your guess?"
choice = gets.chomp.to_i
end
puts "You won"
# For loop on a range of fixums
for i in 1..100
puts "Number is #{i}"
end
# For loop on an array of strings
names = ["alex", "philipp", "joe", "marc", "eda"]
for name in names
puts "Hello #{name}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment