Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. /*
  2. * LOOPS:
  3. *
  4. *
  5. * 0. A loop usually has one or more of the following features: a counter, an exit condition, and an
  6. * iterator. Loops can execute a block of code a number of times. Loops are handy if you want to run
  7. * the same code over and over again, each time with a different value.
  8. *
  9. * 1. JavaScript supports different kinds of loops: for, for/in, while, do/while. A for loop loops through
  10. * a block of code a number of times. A for/in loops through the properties of an object. A while loop
  11. * loops through a block of code while a specified condition is true. A do/while also loops through a
  12. * block of code while a specified condition is true.
  13. */
  14.  
  15. // For Loop //
  16. for(var i = 0; i < 11; i++) {
  17. console.log([i]);
  18. }
  19.  
  20. // For/In Loop //
  21. var person = {firstName:'Wonder', lastName:'Woman', age:150};
  22.  
  23. for (var key in person) {
  24. console.log(person[key]);
  25. }
  26.  
  27. // While //
  28. var count = 1;
  29. while (count < 11){
  30. console.log(count);
  31. count++;
  32. }
  33.  
  34. // Do/While //
  35. var i = 0;
  36. do {
  37. i += 1;
  38. console.log(i);
  39. } while (i < 5);
  40.  
  41.  
  42. /*
  43. * The do/while loop is a variant of the while loop. This loop will execute the code block once,
  44. * before checking if the condition is true, then it will repeat the loop as long as the condition is true.
  45. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement