Page 1 of 1

About Question enthuware.ocpjp.v17.2.3363 :

Posted: Thu Dec 29, 2022 1:38 am
by shwetagulati
can anyon explain how while loop without braces work, it should ideally control one statement if it is without braces but that understanding doesnot match with the output of this program when run:

Output when it is run in commandline:

data written W0 D1
data written W0 D2
data written W0 D1
data written W0 D2
data written W1 D1
data written W1 D2
data written W1 D1
data written W1 D2
data written W2 D1
data written W2 D2
data written W2 D1
data written W2 D2
data written W3 D1
data written W3 D2
data written W3 D1
data written W3 D2
data written W4 D1
data written W4 D2
data written W4 D1
data written W4 D2

Re: About Question enthuware.ocpjp.v17.2.3363 :

Posted: Thu Dec 29, 2022 4:09 am
by admin
Yes, when you have a while loop without { and } then the loop has only 1 statement. But in the given code, that statement is just a semicolon. So, here, only the while condition keeps executing until it is false.