Created
July 12, 2017 08:48
-
-
Save Papillard/0c501a5fe288f490397c0d8ecc55f10b to your computer and use it in GitHub Desktop.
Basic loops with while and for
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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