Ask Question

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?

+1
Answers (1)
  1. 18 March, 04:23
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers