Ask Question
14 August, 19:12

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?

+4
Answers (1)
  1. 14 August, 22:43
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers