Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

general C++ question

Options
  • 03-04-2009 4: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 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 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 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