-
[Ruby] While Loopcoding for food 2022. 7. 21. 09:53
def repeatHello () counter = 1 while counter <= 5 # 조건. while this condition is true, you keep running the loop once that condition hit false, you stop running it. puts "Hello" # while 은 조건문 a Boolean true or false. counter += 1 end end repeatHello ()
while Loops
- while the conditions of a loops is true, keep running the loops.
- once the condition is false, stop the loops.
def printNums (min, max, step) i = min while i <= max puts i i += step end end printNums (0, 10, 2) puts---------------- 0 2 4 6 8 10