Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="description" content="Control Flow">
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width">
  7. <title>JS Bin</title>
  8. </head>
  9. <body>
  10.  
  11. <script id="jsbin-javascript">
  12. // CONTROL FLOW
  13.  
  14. // Control flow deals with providing ways for our code to fork
  15. // depending on what happens.
  16. // The basic way to do this is with if/else if/else statements.
  17.  
  18. // These work basically how they are named.
  19.  
  20. // IF a certain condition is reached then something will happen
  21.  
  22. // If something ELSE is reached then something else happens
  23.  
  24. // You can have as many senarios as you want, but they must go
  25. // If => Else if => Else
  26.  
  27. // In order to use an If/else statement:
  28. // First call the if/else if/else
  29. // Then for if/else if you put a condition in parenthesis
  30. // Then put whatever code you want to happen in curly braces
  31. // If you are using an else statement, it should come last
  32. // You don't need a condition because it will happen
  33. // automatically if no other conditions are met.
  34.  
  35. // Syntax:
  36.  
  37. // if(conditon) {what should happen}
  38. // else if(new condition) {what should happen}
  39. // else {what should happen in other conditions}
  40.  
  41. // There are also SWITCH statements
  42.  
  43. // Switch statements can be used similarly, but are more useful
  44. // when there are many different conditions.
  45. // In order to use a switch statement:
  46. // Declare a switch statement, and put in parenthesis the expression
  47. // The expression is what you want to check for, or the condition
  48. // Then, in curly braces, you put what you expect as your CASES
  49. // Declare each case, and then a colon, followed by the code to
  50. // execute if that case is true.
  51. // After each case you have to put a BREAK or the code will blend together.
  52. // You can purposely exclude breaks to have multiple cases reach the
  53. // same code to execute.
  54. // At the end you can leave a DEFAULT code, for if the code doesn't
  55. // reach any of the cases.
  56.  
  57. // Syntax:
  58.  
  59. // switch(expression) {
  60. // case x:
  61. // code to execute;
  62. // break;
  63. // case y:
  64. // code to execute;
  65. // break;
  66. // case z:
  67. // case 0:
  68. // case 1:
  69. // case 2:
  70. // code to execute;
  71. // break;
  72. // default:
  73. // automatic code;
  74. // }
  75. </script>
  76.  
  77.  
  78.  
  79. <script id="jsbin-source-javascript" type="text/javascript">// CONTROL FLOW
  80.  
  81. // Control flow deals with providing ways for our code to fork
  82. // depending on what happens.
  83. // The basic way to do this is with if/else if/else statements.
  84.  
  85. // These work basically how they are named.
  86.  
  87. // IF a certain condition is reached then something will happen
  88.  
  89. // If something ELSE is reached then something else happens
  90.  
  91. // You can have as many senarios as you want, but they must go
  92. // If => Else if => Else
  93.  
  94. // In order to use an If/else statement:
  95. // First call the if/else if/else
  96. // Then for if/else if you put a condition in parenthesis
  97. // Then put whatever code you want to happen in curly braces
  98. // If you are using an else statement, it should come last
  99. // You don't need a condition because it will happen
  100. // automatically if no other conditions are met.
  101.  
  102. // Syntax:
  103.  
  104. // if(conditon) {what should happen}
  105. // else if(new condition) {what should happen}
  106. // else {what should happen in other conditions}
  107.  
  108. // There are also SWITCH statements
  109.  
  110. // Switch statements can be used similarly, but are more useful
  111. // when there are many different conditions.
  112. // In order to use a switch statement:
  113. // Declare a switch statement, and put in parenthesis the expression
  114. // The expression is what you want to check for, or the condition
  115. // Then, in curly braces, you put what you expect as your CASES
  116. // Declare each case, and then a colon, followed by the code to
  117. // execute if that case is true.
  118. // After each case you have to put a BREAK or the code will blend together.
  119. // You can purposely exclude breaks to have multiple cases reach the
  120. // same code to execute.
  121. // At the end you can leave a DEFAULT code, for if the code doesn't
  122. // reach any of the cases.
  123.  
  124. // Syntax:
  125.  
  126. // switch(expression) {
  127. // case x:
  128. // code to execute;
  129. // break;
  130. // case y:
  131. // code to execute;
  132. // break;
  133. // case z:
  134. // case 0:
  135. // case 1:
  136. // case 2:
  137. // code to execute;
  138. // break;
  139. // default:
  140. // automatic code;
  141. // }</script></body>
  142. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement