1.

Explain while loop in Python programming language.

Answer»

The syntax of a while loop in Python programming language is while expression: 

statement(s) 

Here statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any nonzero value. The loop iterates while the condition is true. 

When the condition becomes false, program control passes to the line immediately following the loop. In Python, all the statements indented by the same number of character spaces after a programming construct are considered to be part of a single block of code. Python uses indentation as its method of grouping statements.

Example

# !/usr/bin/python

count=0

while (count < 9):

print ‘The count is:’,count

count=count +1

print “Good bye!”

OUTPUT

The count is: 0

The count is: 1

The count is: 2

The count is: 3

The count is: 4

The count is: 5

The count is: 6

The count is: 7

The count is: 8

Good bye!



Discussion

No Comment Found