I don't think you understand what your loops are doing. Plus, section is an uninitialized variable when you first access it in your while statement.
Run the code below and and try to understand what it's doing and why. Then rework your code and post it back if you're still having troubles.