Professional Documents
Culture Documents
Term 1-2023-24
Computer Science Worksheet - 1
Grade:10
Topic: While – Do While -- Nested For Loop
Learning Objective: 1. Learn the use of while, do while and nested for loop.
2. Write programs using the while, do while and nested for loop
_______________________________________________________________________________________
2. Identify 2 block of codes from the options given below which produce the same output.
a.
a) for(int i=1;i<5;i++)
{ System.out.println(2*i+1);}
b) for(int i=3;i<=9;i=i+2)
{ System.out.println(i);}
c) for(int i=1;i<=9;i=i+2)
{ System.out.println(i);}
3. Tick the option(s) where the loop terminates without even executing once.
a) for (int k=0;k>=10; k--) {System.out.println(“Hello”); }
b) for (int k=0; k<0; k++) { System.out.println(“Hello”); }
c) for (int j=0;j>=0;j++); { System.out.println(“Hello”); }
1
4. Write the outputs for the following code snippets:
a) b)
int i = 0; int k = 1;
while (i <= 5) { do {
System.out.println(i); System.out.print(k + " ");
k += 2;
i++;
} while (k < 10);
}
1
31
531
7531
97531
*********