Getting started with JavaScript: 005-Basic JS statements
The basic statements of JS are as follows. Let's take a look at the loop statements and selection statements.
Loop statement
1. for Loop
For (var I = 1; I <100; I ++) {// code}
2. do... while loop
Var I = 0; do {I ++; // code} while (I <100 );
3. Traverse
Var array = new Array (); array [0] = "you know"; array [1] = "over"; array [2] = "Haha "; array [3] = "Tigger"; for (var item in array) {document. write (item );}
Since it is a loop, the break and continue are naturally the same.
for (var i = 1; i < 100; i++) { if (i == 99) { break; } if (i % 2 == 0) { continue; } alert(i.toString()); }
Select statement
1. if... else
This is too simple.
2. switch
It is used in the same way as other languages.
var flag = ""; switch (flag) { case 1: break; case 2: break; default: alert(flag); break; }
These statements are basically the same as the programming languages we usually use. The definitions, declarations, and assignments of variables are the same.