javascript - Loops breaks before it ended -


this loop breaks on first time execute. why.

<script>  ( var = 0; < 10 ; i++ ) {      console.log(i);      if ( = 5 ) {         console.log (i);         break;     }   }  </script> 

output : 0 5

i'm expecting : 0 1 2 3 4

use double/triple comparison operator in if statement == or ===

<script>     ( var = 0; < 10 ; i++ ) {          console.log(i);          if ( == 5 ) {             console.log (i);             break;         }       } </script> 

also, output 0 1 2 3 4 5 5. if want output 0 1 2 3 4, should use following code in place of current if statement.

if ( == 4 ) {     break; }  

Comments

Post a Comment

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

python - Scapy Dot11ReassoReq -