0
0
Javascriptprogramming~15 mins

Continue statement in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the Continue Statement in JavaScript Loops
📖 Scenario: You are working on a simple program that processes a list of numbers. Sometimes, you want to skip certain numbers based on a condition and continue with the rest.
🎯 Goal: Build a JavaScript program that uses the continue statement inside a for loop to skip even numbers and print only odd numbers from a list.
📋 What You'll Learn
Create an array called numbers with the values [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].
Create a variable called skipEven and set it to true.
Use a for loop to go through each number in numbers.
Inside the loop, use an if statement to check if skipEven is true and the current number is even.
If the number is even and skipEven is true, use the continue statement to skip printing that number.
Print only the numbers that are not skipped.
💡 Why This Matters
🌍 Real World
Skipping certain items in a list is common when filtering data, such as ignoring invalid entries or focusing on specific values.
💼 Career
Understanding how to control loops with continue helps in writing efficient code for data processing, web development, and automation tasks.
Progress0 / 4 steps
1
Create the numbers array
Create an array called numbers with these exact values: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].
Javascript
Need a hint?

Use const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; to create the array.

2
Add the skipEven variable
Create a variable called skipEven and set it to true.
Javascript
Need a hint?

Use const skipEven = true; to create the variable.

3
Use a for loop with continue to skip even numbers
Use a for loop with the variable i to go through numbers. Inside the loop, use an if statement to check if skipEven is true and numbers[i] is even. If so, use continue to skip to the next number.
Javascript
Need a hint?

Use for (let i = 0; i < numbers.length; i++) to loop. Use if (skipEven && numbers[i] % 2 === 0) to check even numbers and continue; to skip them.

4
Print the numbers that are not skipped
Print each number inside the loop that is not skipped by the continue statement using console.log(numbers[i]).
Javascript
Need a hint?

Use console.log(numbers[i]) to print the numbers that are not skipped.