While loop does the exact same thing what “if statement” does, but instead of running the code block once, they jump back to the point where it began the code and repeat the whole process again.

The syntax of while loop is as follows:

while expression
Statement

The example of while loop is as follows:

x=0
#define a while loop
while(x <4):
        print(x)
        x = x+1