infinite while loop in C Programming language

Given Diagram is the flowchart how infinite while loop works in c programming.
"The condition is always true or 1 in the infinite while loop and never going to be False or 0, the control never comes out of the loop, and forms an Infinite Loop as shown in the the diagram."
Infinite while loop forms when a piece of code that lacks the exit condition so that it repeats indefinitely.
Let us understand infinite while loop from given diagram.
First, we Declare and initilize counter=1. Next The control jumps inside the the loops test condition, the condition is true i.e. counter==1 or true.
The loop’s entering condition is true.If the condition is true then we enter the loop and executes "C statements" present there.
Control jumps back to test condition counter==1 or true , our loop’s condition always remains true. Because of this effect, our loop runs to infinity. This endless loop will only stop either when the application terminates or the system crashes.


Syntax of infinite while loop in C:

Let us study real-world syntax of infinite while loop and then we will look detail into all parts of the infinte while loop.

a.
/* statements outside loop.
Declare and initilization of counter */
int counter=1;
  while(counter==1)
  {
     /* Statements inside body of loop */
    / * Statements to be executed */
  }
// statement outside loop
b.
/* statements outside loop.
Declare and initilization of counter */
  while(true)
  {
     /* Statements inside body of loop
     Statements to be executed */
  }
// statement outside loop


Syntax Explanation :
a. The condition counter==1 inside the while(counter==1) is always true so the "Statements inside body of loop" executes infinite number of times and never stops as there is no exit condition mentioned .
it is always better to avoid using of infinite loop in programming.
b.The condition true inside the while(true) is also always true so the "Statements inside body of loop" executes infinite number of times and never stops as there is no exit condition mentioned .


C program to illustrate use of infinite while loop

/* C program given below displays "This is an infinite while Loop example" */
#include <stdio.h>
int main()
 {
  printf("\n Infinite While loop Demonstration");
  while(1)
   {
    printf("\n This is an infinite while Loop example");
   }
  return(0);
 }


Output:

Infinite While loop Demonstration


This is an infinite while Loop example
This is an infinite while Loop example
This is an infinite while Loop example
This is an infinite while Loop example
This is an infinite while Loop example
This is an infinite while Loop example
.............
........
.....
....

Explanation :   printf("\n Infinite While loop Demonstration");

Shows the message on console.
Infinite While loop Demonstration
Next control enters into the while(1) loop and test the condition
i.e. while (1) which is true then control enters into the body of while loop and executes the
printf("\n This is an infinite while Loop example"); statement.
which shows the output "This is an infinite while Loop example" .
Next control jumps back to while(1) to test the condition and here the condition is true i.e while(1).
after that the statements inside while loop body
i.e. printf("\n This is an infinite while Loop example"); executes.
and the the lopp continues infinite times as the condition while(1) is always true.
The infinite while (1) loop may stops when the system crashes or the application terminates.