+ 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?

12th Sep 2017, 5:01 AM
Топчий Анастасия Александровна
Топчий Анастасия Александровна - avatar
3 Réponses
+ 1
@Tony I asked, because it is the wrong answer in versus :/
12th Sep 2017, 5:28 AM
Топчий Анастасия Александровна
Топчий Анастасия Александровна - avatar
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.
12th Sep 2017, 5:04 AM
Mikhael Anthony
Mikhael Anthony - avatar
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.
12th Sep 2017, 6:08 AM
Mikhael Anthony
Mikhael Anthony - avatar