JS While loops

Ace your homework & exams now with Quizwiz!

(Javascript) Instead of a *while* loop, you can always use a ______ loop.

for

(Javascript) Code the rest of the while loop. With each loop, add the value of i to total, which has been declared beforehand. The loop runs 100 times. while (i <= 99) {

total = total + i; i++; }

(Javascript) Code a while loop that looks for "pig" in the array. When it finds it, an alert displays saying, "Found it!" Use the length of the array as the loop limiter. Break out of the loop when it's found.

var i = 0; while (i < animals.length) { if (animals[i] === "pig") { alert("Found it!"); break; } i++; }​

(Javascript) Code an alert that loops 3 times, alerting the value of the counter each time.

var i = 0; while (i <= 2) { alert(i); i++; }

(Javascript) Code the statement that needs to run above this line of code. while (i <= 144) {

var i = 0; or some other number besides 0.

(Javascript) The first line of a while operation sets the counter. *Type the keyword that begins the second line*, plus the 2 characters that follow the keyword

while (

(Javascript) Code the first line of a while loop. The loop runs as long as i is less than 6.

while (i < 6) {

(Javascript) Code a *while* loop that runs twice and does nothing. The counter i has already been declared and assigned 0.

while (i <= 1) { i++; }

(Javascript) Code a while loop that adds *i* to *tot* with each iteration. Use i > 0 as the loop limiter. var tot = 0; var i = 10;

while (i > 0) { tot = tot + i; i--; }

(Javascript) What is the last character of the first line of a while statement?

{

(Javascript) Type the last line of a while statement.

}


Related study sets

Assignment 8 - Purpose of Underwriting

View Set

Chapter 47: Intestinal and Rectal Disorders (SATA only)

View Set

Honan-Chapter 9: Nursing Management: Patients With Upper Respiratory Tract Disorders

View Set

Strategic Management Chapter 9: Strategic Alliances

View Set