Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

733 views

Published on

No Downloads

Total views

733

On SlideShare

0

From Embeds

0

Number of Embeds

108

Shares

0

Downloads

16

Comments

0

Likes

2

No embeds

No notes for slide

- 1. While Loops! The value of the variable i AFTER the highlighted line has been executed is shown here.
- 2. i = 3 while i > 0 puts i.to_s i = i – 1 end the variable i is assigned an initial value of 3 i = 3
- 3. i = 3 while i > 0 puts i.to_s i = i – 1 end i currently has a value of 3 making i > 0 true i = 3
- 4. i = 3 while i > 0 puts i.to_s i = i – 1 end the while condition is true, step into the code block i = 3
- 5. i = 3 while i > 0 puts i.to_s i = i – 1 end subtract 1 from the i variable i = 2
- 6. i = 3 while i > 0 puts i.to_s i = i – 1 end the end of the code block has been reached return to the while statement i = 2
- 7. i = 3 while i > 0 puts i.to_s i = i – 1 end i currently has a value of 2 making i > 0 true i = 2
- 8. i = 3 while i > 0 puts i.to_s i = i – 1 end i = 2
- 9. i = 3 while i > 0 puts i.to_s i = i – 1 end i = 1
- 10. i = 3 while i > 0 puts i.to_s i = i – 1 end return to the while statement the end of the code block has been reached i = 1
- 11. i = 3 while i > 0 puts i.to_s i = i – 1 end i currently has a value of 1 making i > 0 true i = 1
- 12. i = 3 while i > 0 puts i.to_s i = i – 1 end i = 1
- 13. i = 3 while i > 0 puts i.to_s i = i – 1 end i = 0
- 14. i = 3 while i > 0 puts i.to_s i = i – 1 end the end of the code block has been reached return to the while statement i = 0
- 15. i = 3 while i > 0 puts i.to_s i = i – 1 end i is now equal to 0 making i > 0 false i = 0
- 16. i = 3 while i > 0 puts i.to_s i = i – 1 end i is now equal to 0 making i > 0 false because the while condition is false, the code block is skipped and in this case, the program ends i = 0

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment