# while condition is Truecount = 0while count < 5: print(count) count += 1#ans: 0, 1, 2, 3, 4
# countdownx = 3while x > 0: print(x) x -= 1#ans: 3, 2, 1
# infinite loop with breakx = 0while True: x += 1 if x > 5: break#ans: x is 6
# increment by different valuesx = 0while x < 10: x += 2#ans: x is 10 (after last iteration)
# what is count after?count = 0while count < 5: count += 1#ans: count is 5
# how many prints?x = 3while x > 0: print(x) x -= 1#ans: 3 prints (3, 2, 1)
# what happens?x = 0while x < 5: x += 2#ans: x is 6 (after last iteration)
# infinite loop?x = 0while x >= 0: x += 1 if x > 5: break#ans: x is 6 (breaks when x becomes 6)
# what is x?x = 10while x > 0: x -= 3#ans: x is -2 (10, 7, 4, 1, -2)
# condition never true?x = 0while x > 0: x += 1#ans: loop never runs, x is 0
# what prints?x = 1while x <= 4: print(x) x *= 2#ans: 1, 2, 4
# tricky: what is x?x = 0while x < 3: x += 1else: x += 10#ans: x is 13 (3 + 10)
# what is final value?x = 100while x > 1: x = x // 2#ans: x is 0 (100, 50, 25, 12, 6, 3, 1, 0)
# condition check?x = 5while x: x -= 1#ans: x is 0 (5, 4, 3, 2, 1, 0)
Google tag (gtag.js)