Apologies for the late reply.
For me, keeping a track of nested blocks of code has always been a matter of format.
That is, I find it always helps to keep my scope delimiters (curly braces) vertically aligned.
Some people do it like this
1 2 3 4 5 6
|
while (condition){
//loop content
while (anotherCondition){
//another loop
}
}
|
Once you have nested loops though, neglecting to put your opening scope delimiter one line after the while statement (or whatever you're doing) can make things hairy. So I always do it like this
1 2 3 4 5 6 7 8
|
while (condition)
{
//loop content
while (anotherCondition)
{
//another loop
}
}
|
It becomes, for me at least, much easier to see where something begins and ends by vertically aligning the symbols. It makes the file a bit longer, in terms of line count, but I'm not sure if it affects anything else like the program's performance and time needed to compile.
Most modern IDEs, by the way, have a feature where if you highlight a curly brace by hovering over it with your mouse or by selecting it, the IDE will highlight its corresponding scope delimiter, wherever it is, elsewhere in the program. Try it!
---
Other matters:
Once a program becomes large enough, no single human brain is capable of grasping it all at once. Instead, you delegate tasks in an organized manner (using design patterns and algorithms, about which there are many books written) in such a way that you only have to think about individual specialized parts of the program.
This is why we have development teams, and large single-human projects are considered painstaking and ambitious.
There are also UML diagrams:
http://www.youtube.com/watch?v=OkC7HKtiZC0&list=PLGLfVvz_LVvQ5G-LdJ8RLqe-ndo7QITYc
UML stands for "Unified Modeling Language." It's a diagram notation system used to model complex programs across many languages.
I'm learning about them right now, and while they're overwhelming, they're often essential to professional work done by large teams. Learning about them now will save you a lot of headaches later.