1
2
3
4
5
6
7
8
9
10
To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to CodePen.
0,1,2,3,4,5,6,7,8,9
0
0
0
0
A while loop is an alternative to a loop you studied earlier: a ____ loop. | for | for | |
In a _____ loop, the counter is always initialized before the loop code begins. | while | while | |
i has been assigned 0. Code the first line of the while loop. The loop keeps running as long as i is less than 6. | while (i < 6) { | while\(i<6\){ | |
I've coded two lines. Code the rest of the while loop. With each loop, add the value of i to total, which has been declared beforehand. | let i = 0; while (i < 100) { |
total = total + i; i++; } |
total=total\+i;[\r\n]i\+\+;[\r\n]} |
i starts at 0. Code the statement that needs to run above this line of code. | while (i < 144) { | let i = 0; | leti=0; |
Code a while loop that runs twice and does nothing. The counter i has already been declared and assigned 0. | while (i < 2) { i++; } |
while\(i<2\){[\r\n]i\+\+;[\r\n]} | |
Code the line of a while loop that begins with while. The loop runs as long as i is greater than 10. | while (i > 10) { | while\(i>10\){ | |
I've declared two variables, assigning values to them. Code a while loop that adds i to tot with each iteration. Use i > 0 as the loop limiter. The loop counts down, decrementing by 1. | let tot = 0; let i = 10; |
while (i > 0) { tot = tot + i; i--; } |
while\(i>0\){[\r\n]tot=tot\+i;[\r\n]i--;[\r\n]} |
|
|||
|