+ 3
I don't understand why two codes shows different results. Can anyone explain to me ?
I have attached two javascript code. Have a good look. https://code.sololearn.com/WBTs2RdB5FoJ/?ref=app
4 Antworten
+ 3
Thanks for your response.
+ 2
thats because the second while loop is exactly the same, but it is only printed after the while loop has finished
function(){
while(){}
}
document.write();
^this should be inside the while loop to output the same as the first one
+ 2
no problem
0
The two codes shows different results as
in the 1st code the [ document.write(); ] is inside the while loop so it will print the output of each iteration of the while loop....
but in the 2nd code the [ document.write(); ] is outside the while loop so it will print the final output of the while loop....
i hope you understand it..!!
to make it the same output place the [ document.write(); ] of the 2nd code inside the while loop, like this:
[
//First code
document.write("First Code<br/>");
var x=0;
while(x<4){
document.write(x+ "<br/>");
x++;
}
document.write("<hr/>Second Code<br/>");
//Second code
var y=0;
while(y<4) {
document.write(y+ "</br>");
y++;
}
//document.write(y);
]