<HTML><HEAD><TITLE></TITLE></HEAD>
<BODY>
<script LANGUAGE=Javascript>
for( var i=1; i < 5; ++i )
switch (i){
case 1:
document.write( "Eanie ");
case 2: case 4: case 3:
document.write("Meany ");
break;
default:
document.write("Miney Moe<br>");
}
</SCRIPT>
</BODY></HTML>
Tracing some code
Page 1 of 11 Replies - 1056 Views - Last Post: 15 September 2012 - 02:57 PM
#1
Tracing some code
Posted 15 September 2012 - 12:01 PM
Hi, I just got through trying this code and the output I got was Eanie, Meany, Meany, Meany. However, when I test it on w3schools, Eanie Meany Meany Meany Meany is the correct output, why is that? Var i only ever gets to a value of 4 which means that based on this code it should print Meany three times.
Replies To: Tracing some code
#2
Re: Tracing some code
Posted 15 September 2012 - 02:57 PM
I wouldn’t concern myself with test results from w3schools. what counts is the browsers you and your users use.
besides that, w3schools is formally right. since you don’t have a break statement after the first case, it would fall through and print the first of the four Meanies. though there might be differences in browsers interpreting those cases.
besides that, w3schools is formally right. since you don’t have a break statement after the first case, it would fall through and print the first of the four Meanies. though there might be differences in browsers interpreting those cases.
This post has been edited by Dormilich: 15 September 2012 - 02:59 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|