Posts

Showing posts with the label range

14.Looping(Iteration )Statement- while, for

Image
We know that computers are often used to automate the repetitive tasks. One of the advantages of using computer to repeatedly perform an identical task is that it is done without making any mistake. Loops are used to repeatedly execute the same code in a program. Python provides two types of looping constructs: 1) while statement 2) for statement 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. We generally use this loop when we don't know the number of times to iterate beforehand. Syntax of while Loop in Python  while test_expression:       Body of while In the while loop, test expression is checked first.The body of the loop is entered only if the test_expression evaluates to True. After one iteration, the test expression is checked again. This process continues until the test_expression evaluates to False. In Python, the body of the while loop is determined through indentation.The body starts with ind