The way if statements can be nested, similarly while and for can also be nested loop work, look at the program given below.
When you run this program, you will get the following output .
Here for each value of r, the inner loop is cycled through twice, with the varible c taking value from 1 to 2. The inner loop terminates when the value of C exceed 2, and the outer loop terminates when the value of r exceed 3.
As you can see, the body of the outer for loop is indented, and the body of the inner for loop is further indented. These multiple indentation make the program easier to understand.
Instead of using two statement, one to calculate sum and another to print it out, we can compect this into one single statment by saying.
The way for loops have been nested here, similarly, two while loops can also be nested. Not only this, a for loop can occur within a while loop, or a while within a for.
Please feedback for my first blog..