- Fork and clone this lab. Then, open it in sublime and run the test suite with the
learn
orrspec
command. - This lab requires you to write a series of methods that use the different looping constructs we've covered in this unit. Read the comments in
simple_looping.rb
. This is the file where you'll be coding your solution. The comments will help you to solve the lab and get the tests passing. - Each method takes in an argument of an integer. If you call one of the methods with an argument of
4
, your method should loop andputs
out a phrase4
times. If you call the same method with an argument of10
, your method should loop andputs
out that phrase10
times. - As you move through the lab, think about the differences between the looping constructs you're utilizing. What are some advantages to using certain constructs? Disadvantages?
Take a look at your spec/simple_looping_spec.rb
file. You'll notice on line 4 that there is a before(:each) do
statement. What is this? This is what's called a before
hook. What this is doing is taking the code that is inside the before
hook's block and executing it at the start of each test (denoted by the it
keyword). For example, this:
it "prints out some witty statement from the 1990's" do
@say_my_name = "Oh snap, Destiny's Child!"
expect(@say_my_name).to eq("Oh snap, Destiny's Child!")
end
can be accomplished by this:
before(:each) do
@say_my_name = "Oh snap, Destiny's Child!"
end
it "prints out some witty statement from the 1990's" do
expect(@say_my_name).to eq("Oh snap, Destiny's Child!")
end
- Bastards Book - Loops
- Ruby Docs - Loop
- Ruby Docs - Times
- Ruby Docs - While
- Ruby Docs - Until
- Ruby Docs - For
View Simple Loops on Learn.co and start learning to code for free.