JavaScript Loops Worksheet

Questions

Question 1

What is the difference between a while loop and a for loop?

A while loop continues to execute a block of code as long as a specified condition is true. A for loop is typically used to iterate over a sequence (such as a list, tuple, or string) or to run a block of code a specific number of times.

Question 2

What is an iteration?

An iteration refers to the process of repeating a set of instructions in a loop until a specific condition is met.

Question 3

What is the meaning of the current element in a loop?

The current element in a loop refers to the specific item from a sequence (like a list, array, or range) that the loop is currently processing during that particular iteration.

Question 4

What is a 'counter variable'?

A counter variable is a variable that is used to keep track of the number of times a particular event or operation occurs within a loop.

Question 5

What does the break; statement do when used inside a loop?

The break; statement is used to exit a loop prematurely, meaning it stops the execution of the loop before it has run its normal course.

Coding Problems

Coding Problems - See the 'script' tag below this h3 tag. You will have to write some JavaScript code in it.

Always test your work! Check the console log to make sure there are no errors.