This is your homework, so I assume you NEED to use the loops and switch statments.
That's O.K, but why are all your loops inner to the privious ones ?
Just take them out to the same "level" and your code is just fine! (part to the low/up mixup).
A tip: Pressing extra 'Enter' & 'Space' is free!
(That's the first thing I did to your code, and the problem became very trivial)