Loops Exercises

  1. Write a while loop that prints out all the numbers from 1 to 25 inclusive.

  2. Write an until loop that prints out all of the numbers that are less than 20 and are not divisible by 6.

  3. Write a method, #sum_up_to(number) that, given a number, sums all the numbers from 1 to that number, inclusive. It should use a while loop internally.

  4. Write a method, print_factors(number) that prints all of the factors of a number, including 1 and the number itself. You'll need to use a while loop, a conditional statement, and the modulo operator!

results matching ""

    No results matching ""