In python programming it may be needed to give statements to execute repeatedly with in another set of statements for repeated actions. Identify from the following names for such statements. Loop Loop Statement statement Nested loop Other:
Answers
Answer:
A petrol attendant performs these steps for each customer, but he does not follow them when there is no customer to serve. He also only performs them when it is his shift. If we were to write a computer program to simulate this behaviour, it would not be enough just to provide the steps and ask the computer to repeat them over and over. We would also need to tell it when to stop executing them.
There are two major kinds of programming loops: counting loops and event-controlled loops.
In a counting loop, the computer knows at the beginning of the loop execution how many times it needs to execute the loop. In Python, this kind of loop is defined with the for statement, which executes the loop body for every item in some list.
In an event-controlled loop, the computer stops the loop execution when a condition is no longer true. In Python, you can use the while statement for this – it executes the loop body while the condition is true. The while statement checks the condition before performing each iteration of the loop. Some languages also have a loop statement which performs the check after each iteration, so that the loop is always executed at least once. Python has no such construct, but we will see later how you can simulate one.
Counting loops are actually subset of event-control loop - the loop is repeated until the required number of iterations is reached.
Explanation: