Loops

What types of loops can be nested?
All types of loops can be nested infinitely. In fact, everything can be nested infinitely, there aren't really any hard limits.
Last edited on
All types of loops can be nested infinitely.


Not outer loops. =P
Huh?
closed account (zb0S216C)
LB wrote:
"In fact, everything can be nested infinitely"

False. "if" statements are limited to 128 levels of nesting.

Wazzak
Last edited on
The limits may constrain quantities that include those described below or others. The bracketed number following each quantity is recommended as the minimum for that quantity. However, these quantities are only guidelines and do not determine compliance.

— Nesting levels of compound statements, iteration control structures, and selection control structures [256].
False. "if" statements are limited to 128 levels of nesting.


I hope this was not discovered by trial and error...
@Oria copypaste is your friend and you'd only have to compile it once or twice to see what your compiler supports.

clang w/ MinGW on default settings can handle somewhere between 512 and 8*512. I only tested 513 and 8*512, the 8*512 crashed and got windows crash handler involved:
http://gist.github.com/344081a347db220f8507

Still, if within one function you've nested down 512+ levels to achieve your goal, you deserve to not be able to compile your code.
Last edited on
Your post made me chuckle Oria. I would imagine that the compiler would have a lot to do with it, although I'm curious what the standard for C++ says. I'd research it if I wasn't at work right now although in reality if you have a 128 nested if loop structure, you probably need to find another more optimal way to perform the operation.
Topic archived. No new replies allowed.