Day 5.5 Exercise 33 While Loops

Here’s my work.
Here’s the link to exercise 33.

Ex33 Code
Ex33 Code
Ex33 Output
Ex33 Output
Ex33a Code
Ex33a Study Drill
Ex33a Output
Ex33a Output

Study Drill

1. Convert this while-loop function to a function that you can call, and replace 6 in the test ( i < 6 ) with a variable.
Done. It is in the study drill picture.

2. Use this function to rewrite the script to try different numbers.
Done, it will prompt for numbers.

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.
Done. It is in my study drill work.

4. Rewrite the script again to use this function to see what effect that has.
Done. I’ve tried 2 different ways. One by just calling it on the function, which does everything in the function. However, I also placed a return command in the function, so if I were to do ‘ puts “#{function}” ‘ , it would do the extra step of calling the return numbers.

5. Write it to use for-loops and (0..6)  range operator. Do you need the incrementor in the middle anymore? What happens if you do not get rid of it?
The incrementor is not really needed. However it does change the output. The reason why is i is always added at the end of the function when you do not increment manually. If you do increment manually, the ending output before the function ends, would be +1 more.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s