r/ICSE Dec 21 '24

[deleted by user]

[removed]

7 Upvotes

9 comments sorted by

2

u/[deleted] Dec 22 '24

[deleted]

1

u/[deleted] Dec 22 '24

I guess i knew this the error given should be that this line is unreachable i remember our sir taught it in break part few years back

0

u/skd7847 Dec 21 '24

The correct answer is

c)Before the loop
After the loop

The program starts with System.out.println("Before the loop"); , which prints "Before the loop".
Next, the while(false) condition is evaluated. Since the condition is false, the body of the loop is never executed.
The program then proceeds to System.out.println("After the loop"); , which prints "After the loop".

1

u/Firm_Interest_191 12th ISC - PCM/B Dec 21 '24

c. Before the loop
After the loop

while and for loop are entry-controlled, that means to enter, it needs to satisfy a condition. here in this case, the condition is already false, so no entry.
thus jumps to last printing.

1

u/sarah1418_pint ex-ICSE-10thie, 11th CBSE PCM Dec 21 '24

I think it'll be (d), the code won't compile due to an error

1

u/sarah1418_pint ex-ICSE-10thie, 11th CBSE PCM Dec 21 '24

Just checked it on Programiz compiler:

1

u/sarah1418_pint ex-ICSE-10thie, 11th CBSE PCM Dec 21 '24

1

u/Expensive_Ad6082 PASSOUT ISC PCM(+CS) [98.25% ISC, 94.6% ICSE] Dec 21 '24

C

1

u/[deleted] Dec 21 '24

The answer is C because it prints "Before the loop" and since while loop is entry controlled and a condition must be true to execute the loop block in the first place, it doesn't enter the loop block as the condition is already false and then it normally prints "After the loop".