answersLogoWhite

0

It is not necessary to avoid infinite loops. You are perhaps confusing infinite loops with endless loops which are to be avoided at all costs. An endless loop is an infinite loop that has no reachable exit condition; the loop will iterate until we forcibly terminate the program.

We use the the term infinite loop in the sense that it is impossible to measure or calculate when the exit point will be hit. the following are all examples of infinite loops in their simplest form:

for (;;) {

// ...

}

while (true) { // ... }

do while (true) {

// ...

}

endless:

// ...

goto endless;

The conditional expressions in each of these loops can never be false thus we cannot easily determine when these loops will exit. We typically use infinite loops when there are many exit conditions to consider and it is either impractical or inefficient to evaluate all of those conditions via the controlling expression alone. We take it as read the exit conditions are contained within the body of the loop.

If the body of the loop has no reachable exit condition then it becomes an endless loop. It is the programmer's responsibility to ensure that all infinite loops can exit at some point.

User Avatar

Wiki User

8y ago

What else can I help you with?

Related Questions

Why it is necessary to avoid infinite loops in program design in C programming?

Infinite loops in any programming language are infinite. As in, they don't stop, unless they are told so somewhere INSIDE the loop. If a loop is allowed to continue infinitely (e.g while(true){} is a valid, truly infinite loop), they will hang up (freeze) the program, or even the computer running it, eating excessive resources, and requiring your user to manually terminate (sigterm, sigkill, task manager, alt+f4) the process.


What is a program called designed to avoid common errors?

utility program


How can you design a glider to avoid a crash landing?

You can never fully avoid but you can limit it risk of


Changing the source that is subjecting the program to risk?

avoid


What are some strategies to avoid getting stuck in an infinite loop in Magic: The Gathering?

To avoid getting stuck in an infinite loop in Magic: The Gathering, players can use cards that have a clear win condition or a finite number of repetitions. Additionally, players can carefully track the number of times a loop has occurred and make sure to follow the game rules to prevent an infinite loop from happening.


When possible you should avoid using variables in a program.?

global


why do you use sampling design in research studies?

To avoid mistakes and correct


What is a good conclusion for a paper on the negative effects of nuclear energy?

I assume you will have mentioned Chernobyl and Three Mile Island in the paper. You could emphasise that both these events were avoidable, and that to avoid such events good design and operating procedures are necessary.


Why is good administration necessary?

To avoid chaos, confusion, misunderstanding, and smooth running, a good administration is always necessary


What is geometry cleanup in hyper mesh?

to avoid un necessary splits


How do you avoid ip ban?

Use a program like hidemyIP or freehideip.


Why is it necessary for a person suffering from diarrhea to drink plenty of water?

To avoid dehydration.