Posts

Showing posts with the label While Loop

Python3 While loop

Image
Python While Loop   WHILE  Loop :               The while loop in python is used to iterate over a block of code as long as the test expression(condition) is true Syntax::            while test_expression:                 body of while    * The body of the loop is entered only if the test_expression is true.  * After one iteration, the test_expression is checked again.  * This process proceeds until the test_expression is false. Flow Chart : Eg:        lst=[10,20,30,40,50]                product=1        index=0        while index<len(lst):               product*=lst[index]               index+=1        print("Product is:{}".format(product))       output:    Product is 14400000 While loop with else:        This is same as for loop, we can use else block with while loop as well. * The else part is executed if the condition of while loop evaluates to false. The while loop can be terminated with the break statement. * In such case ,this is ignored. Hence, a while loop's