Last active
November 5, 2015 17:55
-
-
Save tgaff/b9f84c1bda4a5f7ea055 to your computer and use it in GitHub Desktop.
ruby looping
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
arr = [ 2, 4, 6, 1, 7, 9] | |
arr.each do |element| | |
puts "I'm #{element}." | |
end | |
arr.each_with_index do |element, index| | |
puts "#{element} has index #{index}" | |
end | |
3.times do | |
puts 'ok' | |
end | |
arr.length.times do |index| | |
puts "#{arr[index]} has index #{index}" | |
end | |
something = true | |
while something do # while something is true | |
puts "Do stuff" | |
something = false if gets.chomp == 'stop' | |
end | |
something_else = false | |
until something_else do # do this block until something_else is true | |
puts "Do stuff" | |
something_else = true if gets.chomp == 'stop' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment