-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
624bf38
commit 5fdb63a
Showing
4 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env ruby | ||
|
||
i = 0 | ||
numbers = [] | ||
|
||
while i < 6 | ||
puts "At the top i is #{i}" | ||
numbers.push(i) | ||
|
||
i += 1 | ||
puts "Array numbers contains: #{numbers}" | ||
puts "At the bottom i is #{i}" | ||
end | ||
|
||
puts "The numbers: " | ||
|
||
for num in numbers | ||
puts num | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env ruby | ||
|
||
i = 0 | ||
numbers = [] | ||
|
||
while i < 6 | ||
puts "At the top i is #{i}" | ||
numbers.push(i) | ||
|
||
i += 1 | ||
puts "Array numbers contains: #{numbers}" | ||
puts "At the bottom i is #{i}" | ||
end | ||
|
||
puts "The numbers: " | ||
|
||
#for num in numbers | ||
# puts num | ||
#end | ||
|
||
numbers.each do |num| | ||
puts num | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# Get a number from the command line input | ||
# Convert it to an integer .to_i before we save it to the variable number_got | ||
puts "Gimme a number: " | ||
number_got = gets.to_i | ||
|
||
# Define a method with a really long name | ||
# This method takes one parameter, or argument | ||
# | ||
def take_number_iterate_array_print(number_input) | ||
# I have to set these up in here otherwise the method can't access them | ||
# Assign the starting number i.e. "number_current" to 0 | ||
# Assign an empty array to "numbers" | ||
number_current = 0 | ||
numbers = [] | ||
while number_current < number_input | ||
puts "Number top: #{number_current}" | ||
numbers.push(number_current) | ||
|
||
# Take whatever number_current currently is and add 1 to it and save that back to number_current | ||
# If number_current is 0 we add 1 making it 1 and save that to number_current instead | ||
number_current += 1 | ||
puts "Array: #{numbers}" | ||
puts "Number bottom: #{number_current}" | ||
end | ||
|
||
puts "The numbers: " | ||
|
||
# Iterate over each item in the array "numbers" | ||
# Pass each item to the "num" paramemter, or argument, in the anonymous function | ||
# puts "num", the currently iterated item from the array | ||
numbers.each do |num| | ||
puts num | ||
end | ||
end | ||
|
||
# Call the method | ||
# Pass the number we got from the command line into the method as the parameter, or argument "number_got" | ||
take_number_iterate_array_print(number_got) | ||
|
||
|
||
# Extra Credit: | ||
# 1. Convert this while loop to a function that you can call, and replace 6 in the test (i < 6) with a variable. | ||
# 2. Now use this function to rewrite the script to try different numbers. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# Get a number from the command line input | ||
# Convert it to an integer .to_i before we save it to the variable number_got | ||
puts "Gimme a number: " | ||
number_got = gets.to_i | ||
|
||
puts "Gimme a number to iterate by: " | ||
iterator_got = gets.to_i | ||
|
||
# Define a method with a really long name | ||
# This method takes 2 parameters, or arguments | ||
# | ||
def take_number_iterate_array_print(number_input, increment_by) | ||
# I have to set these up in here otherwise the method can't access them | ||
# Assign the starting number i.e. "number_current" to 0 | ||
# Assign an empty array to "numbers" | ||
number_current = 0 | ||
numbers = [] | ||
while number_current < number_input | ||
puts "Number top: #{number_current}" | ||
numbers.push(number_current) | ||
|
||
# Take whatever number_current currently is and add the increment_by variable to it and save that back to number_current | ||
# If number_current is 0 and the increment_by value is 1 then we add 1 making it 1 and save that to number_current instead | ||
number_current += increment_by | ||
puts "Array: #{numbers}" | ||
puts "Number bottom: #{number_current}" | ||
end | ||
|
||
puts "The numbers: " | ||
|
||
# Iterate over each item in the array "numbers" | ||
# Pass each item to the "num" paramemter, or argument, in the anonymous function | ||
# puts "num", the currently iterated item from the array | ||
numbers.each do |num| | ||
puts num | ||
end | ||
end | ||
|
||
# Call the method | ||
# Pass the number we got from the command line into the method as the parameter, or argument "number_got" | ||
take_number_iterate_array_print(number_got, iterator_got) | ||
|
||
|
||
# Extra Credit: | ||
# 3. Add another variable to the function arguments that you can pass in that lets you change the + 1 on line 8 so you can change how much it increments by. | ||
|