WEB DEVELOPER SITE
PHP7
 

Python while Loop statement


While loop statement syntax

while expression:
   statement(s)

groups of the statement while a condition is true

Example

run = 0 
while (run < 0) :
print 'the run is:', run
run = run +1 
 print "thanks!"
Try it yourself »

Note: when the above code excute the result will be


The run is: 0
The run is: 1
The run is: 2
The run is: 3
The run is: 4 

thanks!



Control statement

terminated the loop current iteration, and continue with the start immediately .

It's used in both while and for loops.

Example

#!/usr/bin/python
for letter control   in     #first example
if letter == 't':
      continue
   print 'Current Letter :', letter


i = 0
while i < 4:  #second example
  i += 1
  if i == 1:
    continue
  print(i)

Try it yourself »

#first result
Current Letter : c
Current Letter : o
Current Letter : n
Current Letter : r
Current Letter : o
Current Letter : l

#second result
2
3
4


Welookups is optimized for learning.Copy right 2018 kumar aditya singh .
All Right Reserved and you agree to have read and accepted our term and condition.
All Rights Reserved.

welookups.com