Skip to Content
Learn
Loops & Iterators
Looping with 'While'

Okay, training wheels off. Let’s see your stuff!

i = 3 while i > 0 do print i i -= 1 end
  1. In the above example, we create a variable called i and set it to 3.
  2. Then, we print out 321 since we execute the loop as long as i is positive.

Instructions

1.

Use a while loop to print out the numbers 1 through 50, inclusive. While the example above counts down, you will want to count up.Use print rather than puts, and don’t forget to increment your variable.

Folder Icon

Take this course for free

Already have an account?