var counter = 1
var stopNum = Int. random(in: 1...10)
while counter < stopNum {
print(counter)
counter += 1
}
// loop to print until the stop condition is met
A while
loop accepts a condition and keeps executing its body code while the provided condition is true
. If the condition is never false, the loop will keep running and the program will get stuck in an infinite loop
Comments