Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. // LOOPS
  12.  
  13. // Loops are ways to run certain lines of code until a
  14. // certain condition is met.
  15. // These conditions are often reaching the end of a predefined sequence.
  16. // To do this loops require creating a variable that
  17. // will explain the length of the loop.
  18. // Each loop has a specific syntax to differentiate itself
  19. // from the others and work in different ways.
  20. // These syntax explain how the variables are defined.
  21.  
  22. // There are several types of loops, including:
  23.  
  24. // FOR
  25. // FOR IN
  26. // WHILE
  27.  
  28. // A FOR loop is an easy way to have code move forward or backward.
  29. // A for loop has three parts to it before you get to its statement.
  30. // * initial expression
  31. // * condition
  32. // * increment expression
  33.  
  34. // Syntax:
  35.  
  36. // for(inintialExpression; condition; incrementExpression)
  37.  
  38. // The INITIAL EXPRESSION is the starting point for your loop.
  39. // This is often represented as a variable "i".
  40. // You must assign this variable a value to start.
  41.  
  42. // The CONDITION tells your code how long it should run.
  43. // Wherever your initial expression starts, this will be its destination.
  44.  
  45. // The INCREMENT EXPRESSION tells your code how it should progress.
  46. // This is where the increment and decrement operators shine.
  47.  
  48. // Example for loop:
  49.  
  50. for(var i = 0; i < 10; i++) {return i;}
  51.  
  52. // In that case, the code would begin at 0 and run until 9.
  53. // It would return each number between 0 and 9.
  54. // You could also go from 9 to 0 by simply swapping the initial expression
  55. // value and condition value, and having the increment expression DEcrement.
  56. // For loops are very useful for things like arrays, but do not
  57. // work on normal objects.
  58. // For example, you could loop through an array using bracket notation.
  59. // In the case of the previous loop, it would be like returning array[i].
  60. // This would not work with an object because objects have keys instead
  61. // of index numbers.
  62.  
  63.  
  64.  
  65. // A FOR IN loop is similar to a for loop, but it can work with objects.
  66. // Its syntax much simpler than a simple for loop.
  67. // You start again by calling for
  68. // Then in parenthesis give a variable to represent the objects properties
  69. // Then say "in"
  70. // Then call the object you want to loop through
  71.  
  72. // Syntax:
  73.  
  74. // for(propertyVariable in object) {code to run}
  75.  
  76. // Example for/in loop:
  77.  
  78. var obj = {key1:1, key2:2, key3:3}
  79. for(i in obj) {return obj[i]} // returns all values of obj
  80.  
  81.  
  82.  
  83. // A WHILE loop will loop WHILE a set condition is still true
  84. // This is similar to a for loop, but with a looser syntax.
  85. // You call WHILE,
  86. // Put a condition in the parenthesis
  87. // The condition should contain a variable that will change
  88. // Variables must be assigned before the loop runs
  89. // Then the code you put in curly braces will run
  90. // as long as the condition is true
  91. // For this loop you must put the increment INSIDE the curly braces.
  92.  
  93. // Syntax:
  94.  
  95. // while(condition) {code to run}
  96.  
  97. // Example of while loop:
  98.  
  99. var n = 10;
  100. while(n > 0) {n--; return n;} // returns 9 through 0
  101. </script>
  102.  
  103.  
  104.  
  105. <script id="jsbin-source-javascript" type="text/javascript">// LOOPS
  106.  
  107. // Loops are ways to run certain lines of code until a
  108. // certain condition is met.
  109. // These conditions are often reaching the end of a predefined sequence.
  110. // To do this loops require creating a variable that
  111. // will explain the length of the loop.
  112. // Each loop has a specific syntax to differentiate itself
  113. // from the others and work in different ways.
  114. // These syntax explain how the variables are defined.
  115.  
  116. // There are several types of loops, including:
  117.  
  118. // FOR
  119. // FOR IN
  120. // WHILE
  121.  
  122. // A FOR loop is an easy way to have code move forward or backward.
  123. // A for loop has three parts to it before you get to its statement.
  124. // * initial expression
  125. // * condition
  126. // * increment expression
  127.  
  128. // Syntax:
  129.  
  130. // for(inintialExpression; condition; incrementExpression)
  131.  
  132. // The INITIAL EXPRESSION is the starting point for your loop.
  133. // This is often represented as a variable "i".
  134. // You must assign this variable a value to start.
  135.  
  136. // The CONDITION tells your code how long it should run.
  137. // Wherever your initial expression starts, this will be its destination.
  138.  
  139. // The INCREMENT EXPRESSION tells your code how it should progress.
  140. // This is where the increment and decrement operators shine.
  141.  
  142. // Example for loop:
  143.  
  144. for(var i = 0; i < 10; i++) {return i;}
  145.  
  146. // In that case, the code would begin at 0 and run until 9.
  147. // It would return each number between 0 and 9.
  148. // You could also go from 9 to 0 by simply swapping the initial expression
  149. // value and condition value, and having the increment expression DEcrement.
  150. // For loops are very useful for things like arrays, but do not
  151. // work on normal objects.
  152. // For example, you could loop through an array using bracket notation.
  153. // In the case of the previous loop, it would be like returning array[i].
  154. // This would not work with an object because objects have keys instead
  155. // of index numbers.
  156.  
  157.  
  158.  
  159. // A FOR IN loop is similar to a for loop, but it can work with objects.
  160. // Its syntax much simpler than a simple for loop.
  161. // You start again by calling for
  162. // Then in parenthesis give a variable to represent the objects properties
  163. // Then say "in"
  164. // Then call the object you want to loop through
  165.  
  166. // Syntax:
  167.  
  168. // for(propertyVariable in object) {code to run}
  169.  
  170. // Example for/in loop:
  171.  
  172. var obj = {key1:1, key2:2, key3:3}
  173. for(i in obj) {return obj[i]} // returns all values of obj
  174.  
  175.  
  176.  
  177. // A WHILE loop will loop WHILE a set condition is still true
  178. // This is similar to a for loop, but with a looser syntax.
  179. // You call WHILE,
  180. // Put a condition in the parenthesis
  181. // The condition should contain a variable that will change
  182. // Variables must be assigned before the loop runs
  183. // Then the code you put in curly braces will run
  184. // as long as the condition is true
  185. // For this loop you must put the increment INSIDE the curly braces.
  186.  
  187. // Syntax:
  188.  
  189. // while(condition) {code to run}
  190.  
  191. // Example of while loop:
  192.  
  193. var n = 10;
  194. while(n > 0) {n--; return n;} // returns 9 through 0</script></body>
  195. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement