Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="description" content="Control Flow">
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- // CONTROL FLOW
- // Control flow deals with providing ways for our code to fork
- // depending on what happens.
- // The basic way to do this is with if/else if/else statements.
- // These work basically how they are named.
- // IF a certain condition is reached then something will happen
- // If something ELSE is reached then something else happens
- // You can have as many senarios as you want, but they must go
- // If => Else if => Else
- // In order to use an If/else statement:
- // First call the if/else if/else
- // Then for if/else if you put a condition in parenthesis
- // Then put whatever code you want to happen in curly braces
- // If you are using an else statement, it should come last
- // You don't need a condition because it will happen
- // automatically if no other conditions are met.
- // Syntax:
- // if(conditon) {what should happen}
- // else if(new condition) {what should happen}
- // else {what should happen in other conditions}
- // There are also SWITCH statements
- // Switch statements can be used similarly, but are more useful
- // when there are many different conditions.
- // In order to use a switch statement:
- // Declare a switch statement, and put in parenthesis the expression
- // The expression is what you want to check for, or the condition
- // Then, in curly braces, you put what you expect as your CASES
- // Declare each case, and then a colon, followed by the code to
- // execute if that case is true.
- // After each case you have to put a BREAK or the code will blend together.
- // You can purposely exclude breaks to have multiple cases reach the
- // same code to execute.
- // At the end you can leave a DEFAULT code, for if the code doesn't
- // reach any of the cases.
- // Syntax:
- // switch(expression) {
- // case x:
- // code to execute;
- // break;
- // case y:
- // code to execute;
- // break;
- // case z:
- // case 0:
- // case 1:
- // case 2:
- // code to execute;
- // break;
- // default:
- // automatic code;
- // }
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">// CONTROL FLOW
- // Control flow deals with providing ways for our code to fork
- // depending on what happens.
- // The basic way to do this is with if/else if/else statements.
- // These work basically how they are named.
- // IF a certain condition is reached then something will happen
- // If something ELSE is reached then something else happens
- // You can have as many senarios as you want, but they must go
- // If => Else if => Else
- // In order to use an If/else statement:
- // First call the if/else if/else
- // Then for if/else if you put a condition in parenthesis
- // Then put whatever code you want to happen in curly braces
- // If you are using an else statement, it should come last
- // You don't need a condition because it will happen
- // automatically if no other conditions are met.
- // Syntax:
- // if(conditon) {what should happen}
- // else if(new condition) {what should happen}
- // else {what should happen in other conditions}
- // There are also SWITCH statements
- // Switch statements can be used similarly, but are more useful
- // when there are many different conditions.
- // In order to use a switch statement:
- // Declare a switch statement, and put in parenthesis the expression
- // The expression is what you want to check for, or the condition
- // Then, in curly braces, you put what you expect as your CASES
- // Declare each case, and then a colon, followed by the code to
- // execute if that case is true.
- // After each case you have to put a BREAK or the code will blend together.
- // You can purposely exclude breaks to have multiple cases reach the
- // same code to execute.
- // At the end you can leave a DEFAULT code, for if the code doesn't
- // reach any of the cases.
- // Syntax:
- // switch(expression) {
- // case x:
- // code to execute;
- // break;
- // case y:
- // code to execute;
- // break;
- // case z:
- // case 0:
- // case 1:
- // case 2:
- // code to execute;
- // break;
- // default:
- // automatic code;
- // }</script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement