You are on page 1of 3

1.

Ina nested loop, Which loop continues to execute and terminates first: the outer loop or the inner

loop?
Ans. Inner loop.
2. Write the syntax of nested for
loop.
Ans. for(initialization expression; condition; update expression)

Statements;
for(initialization expression ; condition; update expression)
Inner for loop body
Statements;

3. Write the syntax of break with label and continue with label.
Ans. break label identifier; continue label identifier;
break?
.What is the difference in break and labelled
Ans. The break statement has two forms: labeled and unlabeled. You saw the unlabeled form in the orevious
statements and to terminate a for, while, or do-while
chapters for terminating the switch construct
statement terminates the loop in which it is residing. A labelled break
loop. In a nested loop, the break the break statement is residing in inner loop.
allows the termination of outer loops even though
statements:
ldentify the e r r o r s in the below nested for
(a) for(int i =
1;i<= 5; it+) {
for(intj1; i<= 10; j++){
=

System.out.print(*");

System.out.println );

Nested For Loops 165


(6) for(int i = 1; i<= 5; i++)
for(intj =
1;j <= 10; it+) {
System.out.print("*");

System.out.println(0:
}
Ans. (a) Line number 2 to be corrected as:

for(intj= lij<=10j++)
(b) Line 2 to be corrected:
for(int = 1:j<=10j++)
7. Write nested for statement that printsn by n multiplication table.
Ans. for(int i= 1;i<=n;i++)
{
for(int j=1;j<=n:j++)
System.out.print(i + * " +j + "=" + (i*j));

System.out.println(0;

Section-B
Long Answer Type Questions
8. WAP to find factorial of first 10 natural numbers.
Ans. Class Factorial

public static void main(int num)

int p =1;
for(int i = num ; i>= 1; i--))

Ppi;
System.out.print("Factorial of" +num + "is" + p);

168 7gether wieh Computer Applications (ICSE) - 9

You might also like