Created
April 15, 2018 00:31
-
-
Save nossidge/fc90c767e5ddd5767a2c784a5a80264a to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# Solution to the below question: | |
# https://codereview.stackexchange.com/questions/191522 | |
# Initialise a variable to store the accumulating total. | |
total = 0 | |
# Start an infinite loop. (When writing these, make sure there's a | |
# 'break' command somewhere within the loop, or it will loop forever) | |
loop do | |
# Prompt the user for their input. | |
puts 'give me a number' | |
# Get the user input and chomp to remove trailing white-space. | |
input = gets.chomp | |
# Break out of the loop if 'stop' was input. | |
break if input == 'stop' | |
# Now that we know the input String is supposed to be a number, | |
# we can convert it to Integer, and add it to the total. | |
total += input.to_i | |
end | |
# Output the final total. | |
puts total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment