+ 1
Question from versus
int k; do { k++; } while (k<0); writeline(k); do-while loop has at least 1 iteration. Thus output of the code is 1?
3 Réponses
+ 1
@Tony I asked, because it is the wrong answer in versus :/
0
of course LOL...
first run K = 0 + 1
on checking IF K LESS THAN 0 for loop back.
it never loop back because K already higher than 0.
0
scenario :
k started with 0
k entered do loop
k received ++ ( k becomes 0 + 1 = 1 )
k goes to checking
is K ( 1 ) Lower than 0 ? Nope , then it out the loop.
if only K is lower than 0 , it stay inside the loop.
but , regardless how many times the loop is ,
write line only occur 1 times , at the very least of the code ,
which is the very last result of k to be written , and it's 1.
so , yes , output is : 1.