forked from hacktoberfest17/programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfor-loop.js
More file actions
22 lines (20 loc) · 858 Bytes
/
Copy pathfor-loop.js
File metadata and controls
22 lines (20 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// FOR LOOP
// -Use for loop when you know exact number of times to run loop
// for ([initialization]; [condition]; [iteration]) {
// [loop body]
// }
// -Initialization: begin a counter variable
// -Condition: expression evaluated before passing through each loop
// -Iteration: statement executed at the end of each iteration, bringing loop closer to completion
// -Loop body: code that runs on each pass through the loop
const dogs = ['Caroga', 'Titan', 'Chief'];
function goodDog(dogs) {
for (let i = 0; i < dogs.length; i++) {
console.log(`Who's a good dog? ${dogs[i]}'s a good dog!'`);
}
return dogs;
}
// goodDog(dogs); => Who's a good dog? Caroga's a good dog!'
// Who's a good dog? Titan's a good dog!'
// Who's a good dog? Chief's a good dog!'
// (3) ["Caroga", "Titan", "Chief"]