Jump to content
  • Advertisement
Sign in to follow this  
AgentX

maximum nested conditionals / loops

This topic is 3857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In C is there (or should there be) a limit to the number of levels of nested conditionals and/or loops? Like if you have an if-else (or switch-case) that calls another function based on the condition, and inside that function is another conditional branch that calls another function, and so on. Is there an arbitrary limit to this kind of nesting? Is there a better way in C to do a menu / sub-menu / sub-menu / sub-menu system without nesting function calls within function calls? I have several books on C, C++, and game programming, but none really cover topics like this. And I am speaking in terms of platform-independence, not using the Win32 API.

Share this post


Link to post
Share on other sites
Advertisement
The maximum number of nested scopes (loops, if statements etc) is probably set by your compiler. If you hit this limit you need to seriously reconsider your design.

The maximum number of successive function calls is limited by the stack. You are quite unlikely to hit this limit unless you are using very deep recursion. You would need to write ALOT of functions for a series of non recursive calls to overflow the stack. (Yes you could overflow the stack in a few calls if you put some enormous data structure on it, but that's just a bad idea all around)

Share this post


Link to post
Share on other sites
Limit nesting to three levels!
Studies have shown that the ability of programmers to understand a loop deteriorates significantly beyond three levels of nesting(Yourdon 1986a)
and I agree since it drives me loopy!
Try breaking it into a routine or simplifying your control structure.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!