answersLogoWhite

0


Best Answer

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

7y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

Not necessary, but users often prefer programs that actually perform their work, instead of running infinitely.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why it is necessary to avoid infinite loop in program design?
Write your answer...
Submit
Still have questions?
magnify glass
imp
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.


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

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


What is a program called designed to avoid common errors?

utility program


Changing the source that is subjecting the program to risk?

avoid


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 do you use sampling design in research studies?

To avoid mistakes and correct


Why is good administration necessary?

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


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

global


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 matter recycles?

The purpose is to avoid pollution and to make economies of materials.


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

To avoid dehydration.