Computer Science, asked by biswajitmondal51118, 6 months ago

A –––––– is a sequence of instructions that is executed repeatedly

either a specified number of times or until some condition is satisfied.​

Answers

Answered by REGMAC
46

Answer:

hello

the answer is loop

hope you mark me as brainiest

also student547 is a hacker

Answered by IshaniDatta
4

Answer:

loop

Explanation:

greet customer

ask for required type of petrol and amount

ask whether customer needs other services

ask for required amount of money

give money to cashier

wait for change and receipt

give change and receipt to customer

say thank you and goodbye

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.

If you wanted to get from Cape Town to Camps Bay, what loop algorithm would you use? If you started by putting your car on the road to Camps Bay, you could:

drive for exactly 15 minutes. After 15 minutes, stop the car and get out.

drive for exactly 8km. After 8km, stop the car and get out.

drive as long as you are not in Camps Bay. When you arrive, stop the car and get out.

The first two algorithms are based on counting – the first counts time, and the second counts distance. Neither of these algorithms guarantees that you will arrive in Camps Bay. In the first case, you might hit heavy traffic or none at all, and either fall short of or overshoot your desired destination. In the second case, you might find a detour and end up nowhere near Camps Bay.

The third algorithm is event-controlled. You carry on driving as long as you are not at the beach. The condition you keep checking is am I at the beach yet?.

Many real-life activities are event-controlled. For example, you drink as long as you are thirsty. You read the newspaper as long as you are interested. Some activities are based on multiple events – for example, a worker works as long as there is work to do and the time is not 5pm.

Similar questions