Home | Computer Science

<
Python

Program

Print i as long as i is less than 6:


Program
INPUT

i = 1 while i < 6: print(i) i += 1

OUTPUT

<
Program

Program

Exit the loop when i is 3:


Program
INPUT

i = 1 while i < 6: print(i) if i == 3: break i += 1

OUTPUT

<
Python

Program

Continue to the next iteration if i is 3:


Program
INPUT

i = 0 while i < 6: i += 1 if i == 3: continue print(i)

OUTPUT

<
Program

Program

Print a message once the condition is false:


Program
INPUT

i = 1 while i < 6: print(i) i += 1 else: print("i is no longer less than 6")

OUTPUT