Javascript is what's known as a sequential programming language. This means that each and every line of code is executed from top to bottom. Quite often, however, you don't want every line to execute - you'll want more control over the way your programmes work. One way to control the flow of your code is with conditional logic.
Block statement
{ statement_1; . . statement_n; }
Conditional statements
if...else statement switch statement
Exception handling statements
You can throw exceptions using the throw statement and handle them using the try...catch statements. The try...catch statement marks a block of statements to try, and specifies one or more responses should an exception be thrown. If an exception is thrown, the try...catch statement catches i
For loop
for loop for statement for (initialization; test condition; iteration statement) {Statements to be executed if test condition is true} for loop
While loop
The while loop loops through a block of code as long as a specified condition is true. while (i < 10) { text += "The number is " + i; i++; }
The Do/While Loop
do { text += "The number is " + i; i++; } while (i < 10);
In all loops: break leaves the loop, continue starts a new loop iteration.
The break statement "jumps out" of a loop.
for (i = 0; i < 10; i++) { if (i === 3) { break; } text += "The number is " + i + "
"; }
The continue statement "jumps over" one iteration in the loop.
for (i = 0; i < 10; i++) { if (i === 3) { continue; } text += "The number is " + i + "
"; }