Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * LOOPS:
- *
- *
- * 0. A loop usually has one or more of the following features: a counter, an exit condition, and an
- * iterator. Loops can execute a block of code a number of times. Loops are handy if you want to run
- * the same code over and over again, each time with a different value.
- *
- * 1. JavaScript supports different kinds of loops: for, for/in, while, do/while. A for loop loops through
- * a block of code a number of times. A for/in loops through the properties of an object. A while loop
- * loops through a block of code while a specified condition is true. A do/while also loops through a
- * block of code while a specified condition is true.
- */
- // For Loop //
- for(var i = 0; i < 11; i++) {
- console.log([i]);
- }
- // For/In Loop //
- var person = {firstName:'Wonder', lastName:'Woman', age:150};
- for (var key in person) {
- console.log(person[key]);
- }
- // While //
- var count = 1;
- while (count < 11){
- console.log(count);
- count++;
- }
- // Do/While //
- var i = 0;
- do {
- i += 1;
- console.log(i);
- } while (i < 5);
- /*
- * The do/while loop is a variant of the while loop. This loop will execute the code block once,
- * before checking if the condition is true, then it will repeat the loop as long as the condition is true.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement