Infinite for loop without condition in C

By: IncludeHelp, on 21 FEB 2017

Learn: How to run an infinite for loop without using condition? Here is a trick to make for loop as an infinite loop without using any value within the loop statement.

We know that, generally for loop has three parts initialization of loop counter, conditional statement and increment/decrement (or updating the loop counter), we can make a for loop infinite without using these three parts.

Here is the statement

for(;;);

Keep blank all three parts and terminate for loop using semicolon. This loop will run as infinitely.

Here is the program

#include <stdio.h>

int main()
{
    printf("Hello\n");
    for(;;);
    printf("world\n");

    return 0;
}

Output

Hello
[Infinite...] "Hey, this line will not print"

Related Tutorials



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.