div { display:none; }

Trending technologies

#AWS #Azure #Blockchain #IOT #machine learning #Virtual Reality #Analytics #Business Intelligence

Tutorials

Blogs

While Loop is a type of loop that is used when you don’t know exactly how many times the code will repeat. The main characteristic of a while loop is that it will repeat a set of instructions based on a condition.

While Loops

Basic While Loop

While Loop Python

Example


i = 1

while i < 6:

print(i)

i += 1

Break Statement

The break statement in programming has the following two usages –

  1. When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.
  2.  It can be used to terminate a case in the switch statement

Example


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

Continue Statement

It forces the next iteration of the loop to take place, skipping any code in between


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

error: Content is protected !!