Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

general C++ question

  • 03-04-2009 03:48AM
    #1
    Closed Accounts Posts: 2


    I was wondering if there was a limit to how many nested statements you could put in a program? For instance, nesting an if...else statement within a switch statement that is within a while statement. Any enlightenment would be appreciated.


Comments

  • Registered Users, Registered Users 2 Posts: 6,240 ✭✭✭hussey


    I was wondering if there was a limit to how many nested statements you could put in a program? For instance, nesting an if...else statement within a switch statement that is within a while statement. Any enlightenment would be appreciated.

    I don't think so - would be all compiler/memory related, but I would assume a couple of hundred thousand


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    I was wondering if there was a limit to how many nested statements you could put in a program?

    Not aware of a limit, but from a coding style standpoint you should avoid doing too many.

    If you need a large number then a recursive method/function would probably be better (at least in maintaining the code).


  • Registered Users, Registered Users 2 Posts: 981 ✭✭✭fasty


    For the sake of programming style, I would say stick to 2 or 3 nested statements.

    I guess if you had LOTS of local variables in the mix or a few large ones, you'd have stack overflow to worry about. But then the same could be said of recursion...


Advertisement