Javascript Loops

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

How many values can you initiate in statement 1 of a for loop?

As many as you want.

When is statement one executed in a for loop?

Before the loop (code block) starts

What is a while loop?

Can execute a specific code as long as condition as true.

What is statement two in a for loop?

Defines the condition for running the loop (code block)

When is statement three in a for loop executed?

Each time after the loop (code block) has been executed

How does statement 2 of a for loop relate to a boolean?

If statement two returns false, it will end the loop. If it returns true, it will keep going.

What is a for/in loop?

It loops through the properties of an object.

Does statement 3 always need to count up in a for loop?

No, it can count down (i--) or perform a different function. It can also be omitted entirely if the increment is defined in the loop.

What does i++ mean?

This increases the value returned by one on each execution.

For Loop: Usage

To run the same code many times and gather a different result each time.

Can you omit statement 1 in a for loop?

Yes, like when your values are defined before the loop begins.

How do you avoid an infinite loop if you omit statement 2?

You must provide a break in the loop.

Do/While Loop: Syntax

do { code block } while (condition);

Do/While Loop: Example

do { text += "The number is" + i; i++; } while(i < 10);

For loop: Syntax

for (statement 1; statement 2; statement 3) { code block to be executed }

For Loop: Examples

var define = boolean; for (i=0, i < variable or number, i++) { //execute code here console.log("Some text" + i + "some more text <br/>"); }

For/In loop: Syntax

var person = {fname:"John", lname:"Doe", age:25}; var text = ""; var x; for (x in person) { text += person[x]; }

While loop: Syntax

while (condition) { //code to be executed }

While loop: Example

while (i < 10) { text += "The number is" + i; i++; }


संबंधित स्टडी सेट्स

Chapter 21: Nursing Management of Labor and Birth at Risk

View Set

Chapter 4 Protein Three-Dimensional Structure

View Set

Cognitive Psychology Chapter 4: Working Memory

View Set

Adult Development and Aging (chapters 1-2)

View Set

Chapter 11 HRM, Chapter 12 HRM, I/O Psych Ch. 1 Test, Ch. 3 - Needs Assessment, 4.1 Employee selection: Recruiting and Interviewing TB, 5.1 Employees selection: References and testing TB, 7.1 Evaluating employee performance tb, 8.1 Designing and Eval...

View Set

Science Chapter 9 Matter and Its Changes Section 1 Physical Properties and Changes

View Set

HIMT1350-Pharmacotherapy- Chapter 19-26

View Set