You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is an unfortunate artifact of the REPL... it always prints the results of the last statement when execution is complete. For instance, if we run the following in the REPL...
> (() => { let i = 0; while (i < 5) { console.log(i); i += 1 } })()
we get.
0
1
2
3
4
undefined
Note the undefined there...
In your example, the last line evaluated that produces a result is the i += 1 that increments i to 5, and therefore 5 ends up being printed. The loop is exiting correctly, it's just the result display looking off.
Another example, perhaps clearer:
> i = 0
0
> while (i < 5) { console.log('...', i); i += 1 }
... 0
... 1
... 2
... 3
... 4
5
>
There has been no activity on this issue for 11 months. The help repository works best when sustained engagement moves conversation forward. The issue will be closed in 1 month. If you are still experiencing this issue on the latest supported versions of Node.js, please leave a comment.
Version
v14.17.5
Platform
Linux XPS 5.15.0-58-generic nodejs/node#64-Ubuntu SMP Thu Jan 5 11:43:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
Enter the node REPL then type
How often does it reproduce? Is there a required condition?
always seems to reproduce
What is the expected behavior?
Entering this code into a file, then executing it with
node file.js
gives the following output as expectedWhat do you see instead?
Additional information
No response
The text was updated successfully, but these errors were encountered: