by Dinesh Thakur Category: Control Structures

In the expression for for loop the inclusion of the expressions are optional. However, two semicolons must be included. An endless for loop may be written as shown below.


In this form there are no expressions, only two semicolons are present. The loop may be stopped by using the statement break; . Program provides an illustration of application of an endless/or loop.

Illustrates an endless for loop and uses break statement to stop it.


void main()
    int Angle =0;
    double PI = 3.14159, RAngle;
    for(;;) //endless for loop
       RAngle = Angle *PI/180;
       printf("Angle= %d deg.\t sin(%d) = %.4lf\n",Angle,Angle, sin(RAngle) );
       Angle = Angle + 45;
       if (Angle >180)
    } // break included to exit from the loop.

The expected output is given below.

     Endless for loop in C

In the above program, an endless for loop is used to calculate sine of an angle, where the value of the angle varies from 0 degrees to 180 degrees. The statement break; is used for getting out of loop when the value increases beyond 180. The header file <math.h> is included in order to use its function sin().For using the sin()function, the angle is converted into radians, because the argument of sin() is the value of angle in radians. The program then calculates the value of sin (angle) and displays it.

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles