Ask Question
3 May, 21:56

What is an infinite loop? What strategies or techniques can you use to prevent infinite loops in a program? Are infinite loops always undesired? Why?

+3
Answers (1)
  1. 4 May, 00:52
    0
    Infinite loop is a loop which don't have any end. It will go into infinite number of iterations

    Explanation:

    Infinite loops are always undesired as it takes more CPU time and system memory. it makes the program unresponsive and user needs to terminate that.

    example:

    int i=5;

    while (i>0) {

    printf ("it is positive number";

    }

    Above is an example of infinite loop where i is always positive number.

    Here we need to either decrement i value in the loop or terminate the loop by using break statement.

    In some programming languages where we have exception handling we can check for "Stack Overflow" Exception which in general caused because of infinite loop. In catch block we can handle that exception
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “What is an infinite loop? What strategies or techniques can you use to prevent infinite loops in a program? Are infinite loops always ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers