Programming Tricks: Can You Answer This? - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Programming Tricks: Can You Answer This? (1649 Views)
| Programming Tricks: Can You Answer This? by dontro(op): 7:35pm On Dec 26, 2017 |
Please see the attached image. Please: 1. Answer before you try it out, 2. Give technical explanation for your answer
|
| Re: Programming Tricks: Can You Answer This? by Nicolars(m): 5:43am On Dec 27, 2017 |
The first answer is 1 A do while loop will do at least one loop irrespective of the condition, that is even if the condition isn't met, the code would still run for the first time. So x is increased by 1 for the first time x=0+1=1; On the second iteration,the loop is broken because the condition is considered and 1 is not less than 0 The second answer is 9. The loop is going to iterate 9 times so if 0 increases by 1 nine times , it will be 9 |
| Re: Programming Tricks: Can You Answer This? by philcz(m): 5:52am On Dec 27, 2017 |
Nicolars:The first answer is one as you rightly said but for the second question I think the answer is 10 not 9 because the loop will run from i=0 to i=9 so k=10 before the loop terminates |
| Re: Programming Tricks: Can You Answer This? by Nicolars(m): 6:12am On Dec 27, 2017 |
philcz:lol... Yh... 0-9 is 10 counts |
| Re: Programming Tricks: Can You Answer This? by philcz(m): 6:17am On Dec 27, 2017 |
Nicolars: yea. Which languages are good in? |
| Re: Programming Tricks: Can You Answer This? by Nicolars(m): 8:47am On Dec 27, 2017 |
| Re: Programming Tricks: Can You Answer This? by philcz(m): 9:08am On Dec 27, 2017 |
Nicolars:Lol.. I see you going far bro.. your logical reasoning is sound |
| Re: Programming Tricks: Can You Answer This? by Nicolars(m): 9:28am On Dec 27, 2017 |
philcz:Lol... This isn't logic at all ![]() This question is like breaking toothpick.. And iroko tree still dey forest |
| Re: Programming Tricks: Can You Answer This? by philcz(m): 9:30am On Dec 27, 2017 |
Nicolars:Breaking the toothpick will give you the courage to face the iroko. Have high expectations. |
| Re: Programming Tricks: Can You Answer This? by dontro(op): 3:33am On Dec 29, 2017 |
Whoops! NONE of you up there got the answer. |
| Re: Programming Tricks: Can You Answer This? by Darey00(m): 7:32am On Dec 29, 2017 |
1 and 1 |
| Re: Programming Tricks: Can You Answer This? by stonemasonn: 9:42am On Dec 29, 2017*. Modified: 10:36pm On Dec 29, 2017 |
The first one can't be 1, as long as X<0, console.log might yield 0 or fail. The second code should yield 9, since index i and variable k both starts with 0 and increments by 1 to i<10. On a second look, I think K = 0. Because K is outside the for{} loop. |
| Re: Programming Tricks: Can You Answer This? by NaHiim: 12:11pm On Dec 29, 2017 |
The first one will display 1 because the code contained within the two braces (do and while) will excecute at least once The second one will display 0 because its a post increment operator(the increment is done after the variable is read) so it will keep on assigning 0 to k. |
| Re: Programming Tricks: Can You Answer This? by Nicolars(m): 1:10pm On Dec 29, 2017 |
Question 1 would give an error Because curly braces shouldn't just come after while(k<0) |
| Re: Programming Tricks: Can You Answer This? by dontro(op): 5:56pm On Dec 29, 2017 |
Nicolars:NOT TRUE. You can have curly braces there, although I don't usually see it used that way. |
| Re: Programming Tricks: Can You Answer This? by Nicolars(m): 7:04pm On Dec 29, 2017 |
dontro:What language is that.... On c++ its not so |
| Re: Programming Tricks: Can You Answer This? by dontro(op): 6:57am On Dec 30, 2017 |
Nicolars:That is the most popular programming language in the world today, a.k.a JAVASCRIPT |
Can You Answer This Question. • LEARN ETHICAL HACKING,TIPS AND TRICKS • Can You Answer This Question. Help Me Learn About It. • 2 • 3 • 4
Download SMS Portal Creator SPC3 For Free (free Licence) • Warri Developers Meetup • OP Auto Clicker 4.0
yea. Which languages are good in?