How many times can we use for loop

How many times can we use for loop in c language.....
i heard that there is a limit for using 'FOR LOOP' in c language....

please clear my doubt.....
What do you mean with that?
means number of for loops..........

like this.....

for(i=0;i<x;i++)
{
//statement
}

for(j=0;j<x;j++)
{
//statement
}

for(k=0;k<x;k++)
{
//statement
}

for(l=0;l<x;l++)
{
//statement
}
.
.
.
.
.
.
N number of times...

like this how many FOR LOOPS can we use
What do you mean? You want to know if there's some kind of limit to the amount of for loops in a program?

There is no limit. You can have as many for loops as you want. By the way, if you're using C++ you can just do this:
1
2
3
for (int i = 0; i < j; i++);
/* i doesn't exist any more */
for (int i =0; i < j; i++);

so you don't have to use the whole alphabet.
closed account (S6k9GNh0)
I will go ahead an throw in that if you find yourself pushing the limits of the compiler for having to many for loops, there are definitely problems with the code you provided.
Last edited on
ofcourse till now i too know that there was no limit for 'FOR LOOPS'...........

but my friend said that there was a limit of using number of for loops in c...

closed account (S6k9GNh0)
Ask your friend the source of his information and that he should read the C or C++ standard documentation.

EDIT: Actually, it's not really mentioned to a limit of the number of times a for-loop could be used (in the standard). I'm almost positive that they assume that it's limitless though. There would be absolutely no reason to place a limit on the amount.
Last edited on
Maybe your friend meant four-loops. In which case the answer is... 4. ;^)

I suppose there must be SOME real-world limitation. But it would probably depend on the amount of memory in your PC and it would be ridiculously large.
Theoretically, there is no limit. But like cnoeval said, the more code you have, the larger your executable file gets (and you can't really optimize this yourself very much with C/C++ (which is why assembly is great, and why writing boot sector programs is a good learning experience)), and therefore the more disk space and memory it will use... not to mention how slow it would be to get through 400 for loops.
Well, technically it would be limited to the size of the data type of your counter..

(unless you create an infinite loop)
No, there is no theoretical limit. The boundary of the data type you use as a counter only limits the amount of iterations you can do (but it doesn't really, because it will just overflow and continue looping... e.g. for (int i = 1; i > 0; i++); will loop until the i overflows and becomes INT_MIN); the sky (and the hard disk) are the only limits to the amount of for loops you can have.
Topic archived. No new replies allowed.