From 46e250be92e73bb4dcf74a6d3f89f6e557bac66d Mon Sep 17 00:00:00 2001 From: Renata Estes Date: Sun, 30 Jul 2017 19:58:05 -0500 Subject: [PATCH 1/2] forloops.js --- 03week/forLoops.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 03week/forLoops.js diff --git a/03week/forLoops.js b/03week/forLoops.js new file mode 100644 index 000000000..a88876338 --- /dev/null +++ b/03week/forLoops.js @@ -0,0 +1,38 @@ +const carsInReverse = ['Fiat', 'Ford']; +console.log(carsInReverse); + +for (let i = 0; i < carsInReverse.length; i++){ + console.log(carsInReverse[i]); +} + +const persons = { +firstName: "Jane", +lastName: "Doe", +birthDate: "Jan 5, 1925", +gender: "female" +}; + +let key; +for (key in persons) { + console.log(key); +} + +for (key in persons) { + if (key ==='birthDate') { + console.log(persons['birthDate']); + } +}; + + +let n = 0; +while (n < 1001) { + console.log(n); + n++ +}; + +/* +A "for loop" is better than a "while loop" when you know the exact number of iterations you need to do for a specific problem. + +The difference between a for loop and a for...in loop is + +The difference between a while loop and a do...while loop is a while loop keeps going until something rings true. The do...while loop when some sort of task or function needs to be done first before you start running that loop. From 8c9e1e78b0192586d61dbe174a3c397ebadebbcc Mon Sep 17 00:00:00 2001 From: Renata Estes Date: Sun, 30 Jul 2017 20:07:57 -0500 Subject: [PATCH 2/2] forLoops --- 03week/forLoops.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/03week/forLoops.js b/03week/forLoops.js index a88876338..8d4134d21 100644 --- a/03week/forLoops.js +++ b/03week/forLoops.js @@ -33,6 +33,6 @@ while (n < 1001) { /* A "for loop" is better than a "while loop" when you know the exact number of iterations you need to do for a specific problem. -The difference between a for loop and a for...in loop is +The difference between a for loop and a for...in loop is a for loop is used to iterate through an array and a for..in loop is to iterate over the properties of an object. -The difference between a while loop and a do...while loop is a while loop keeps going until something rings true. The do...while loop when some sort of task or function needs to be done first before you start running that loop. +The difference between a while loop and a do...while loop is a while loop keeps going until something rings true. The do...while loop when some sort of task or function needs to be done first before you start running that loop.