If a loop is combined in another loop it is said to be a nested loop. In a nested loop the inner loop gets executed completely for each iteration of the outer loop. We can have any number of levels of nested loops.
Consider the following example:
Generally to print a double dimensional array we use nested for loop.
Example:
int a[][]={ {1,2,3}, {4,5,6}, {7,8,9}};
for(int i=0;i<3;i++)
{
System.out.println(“”);
for(int j=0;j<3;j++)
{
System.out.print (“\t”+a[i][j]);
}
0 comments:
Post a Comment