Loops Flashcards

1
Q

while

A
While (condition) { //while this is true
    //excite code
}

while (numb < 20) {
console.log(numb++);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

do while

A

do {
numb+=1;
console.log(numb);
} while (numb < 20);

• do while executes code block first prior to conditional statement i

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

for

A
for (var i = 0; i<20; i++) {
     console.log(i);
}
each time the loop is run 1 is added to the i variable. The loop terminates when i equals 20
• each ; section can have more than 1 expression which you can do by separating with , see next card
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

For loop multi-expression

A
for (var i =0, phrase="hi mom"; i<20; i++) {
       console.log(phrase + " " + I);
}

• notice the , separating the multi-expressions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Nested for loop

A
for (i=1; i<=4; i++) {
   console.log(i + " Outer       loop");
   for (j=1; j<=4;j++) {
       console.log(j + " inner loop");
   }
}
• first loop iterates once. Inner loop 4 times. Then first loop 1 inner loop 4; etc
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Loop

A

• used to repeat statements or task

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

conditional

A
  • a statement that executes code after checking a condition.
  • if something is true, do this. Otherwise, do that
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Loop

A
  • As long as something is true, keep doing this

* e.g. As long as you are thirsty, keep drinking water.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly