A line of code that begins with the "while" needs to end with ":" symbol
Step-by-step explanation:
In python, the while loop statement has ":" at the end of the line.
Syntax:
while expression:
code(s) or statement(s)
Example:
cnt = 0
while (cnt < 5):
print 'cnt:', cnt
cnt = cnt + 1
Like other programming languages, while loop works in the same way except that in python it comes alone with "else" statement. When the condition is false, "else" statement gets executed.
Example:
#!/usr/bin/python
cnt = 0
while cnt < 5:
print cnt, " is less than 5"
cnt = cnt + 1
else:
print cnt, " is not less than 5"