+ 2

Javascript

What is wrong in this code? var s=0; for(s=0;s<=25;s++){ if(5<=s<=10){ continue; } document.write(s+"<br/>"); } PLEASE ANSWER ME...I'M LOOSING MY HEAD!

11th Jan 2017, 10:14 AM
Simone Gramegna
Simone Gramegna - avatar
2 Respostas
+ 7
I think the compound conditional "5<=s<=10" is not valid. Try to split it with an 'and' operator: "5<=s && s<=10".
11th Jan 2017, 10:16 AM
Álvaro
+ 5
@Alvaro is right, it's work with: var s=0; for (s=0;s<=25;s++){ if(5<=s&&s<=10){ continue; } document.write(s+"<br/>"); } Personally, I prefer to be explicit with conditions priority, so I add parenthesis, and sometimes few more space to be better readable: if ( (5<=s) && (s<=10) ) If you have only one instruction in the statement block, the curly brackets are optional, so you can shorten the code like this: for ( var s=0; s<=25; s++) { if ( (5<=s) && (s<=10) ) continue; document.write(s+"<br/>"); } ... or even ( breaking long lines is useful for readability ): for ( var s=0; s<=25; s++) { if ( (5<=s) && (s<=10) ) continue; document.write(s+"<br/>"); }
11th Jan 2017, 12:33 PM
visph
visph - avatar