+ 1
Why do i get timeout message
function main() { var depth = parseInt(readLine(), 10); //your code goes here var x=0 for(i=0;i<=depth;i=i++) { x=x+7-2; if (x==depth){ console.log(i) } } }
2 Respostas
+ 6
i = i++
Is a statement with no effect
Please use the search bar because many had asked questions around this task.
https://www.sololearn.com/Discuss/2624694/?ref=app
https://www.sololearn.com/Discuss/2618113/?ref=app
0
The i=i++ statement performs post-increment and then it makes the assignment, so the assignment overwrites the incremented value with the old value. Here is how it works in pseudo-code:
tmp = i
i = i + 1
i = tmp
You can see the value in i ends the same as it started, so the loop never exits.