- Become familiar with the
whileloop - Practice effectively using logical operations as a looping condition
condition = true
i = 0
while condition
puts "This code will execute until the condition is false"
if i == 3
condition = false
end
i += 1 # incrementing variable
endNote:
Go through the anatomy of this while loops
puts("Input a number!")
num = gets.to_i
while num < 100
puts("That number is too small! Try again!")
# prompt again, re-assign `num`
num = gets.to_i
end
puts("You typed " + num.to_s + " which is at least 100!")-
Write a loop that prints out the numbers 1 - 9.
-
Let's go back to the first example. Write a loop that prints out the statement "Hello, World!" three times with as least code as possible.
-
Given a specific number, write a program that will print
trueif the number is prime andfalseif the number is not.
Note:
Give them the algorithm to determine if a number is prime so they just need to code it out
puts "Print statements forever"
while true
puts "and ever"
end- Finite + Infinite looping using
while - Incrementing / Decrementing Variable
- Logical Operations in Conditions