0
For loop
Hi everyone, What is the difference between these var i ; for ( i = 0; i < 10; i++){ } Vs for(var i = 0; i < 10; i++){ } Vs for(i = 0; i < 10; i ++){ }
8 Respostas
+ 4
A.S. if javascript, the third one is valid, even if unadvised ;P
Mawande Notununu specify the language if you want some chance to get accurate answer ^^
+ 4
A.S. Third one is working fine
https://code.sololearn.com/cE2szvKegQ3z/?ref=app
Hi, Mawande Notununu the purpose of all three ways are same you can use any one!
+ 4
in js all three are same...
at least if in global scope: in local scope the third will implicitly declare 'i' variable in global scope ^^
however this one is slightly different:
for (let i=0; i<10; i++) {
}
as let variables are block scoped ;P
however, no difference in efficiency ;)
+ 3
Mawande Notununu Node.js is an open source, cross-platform runtime environment for developing server-side and networking applications. Node.js applications are written in JavaScript, and can be run within the Node.js runtime on OS X, Microsoft Windows, and Linux.
By Tutorials point
+ 1
Sorry its JS
+ 1
Rishav Tiwari visph sorry actully i dont have much more idea of node i thought this will be invalid if we dont declear variable and its not valid in c cpp java as well as in js also. Thanks for telling this i will edit my answer .
+ 1
Thank very much everyone
0
Third one is invalid becz i variable is no decleared . First and second are valid in c ,cpp and java . please mention language also becz in some language u dont need to declear variable .
but all three loops will print values from
0-9 if u will write print statement inside loop body