0
0
Javaprogramming~15 mins

Continue statement in Java - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the Continue Statement in Java Loops
📖 Scenario: You are working on a 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 Java program that uses the continue statement inside a for loop to skip printing even numbers and only print odd numbers from 1 to 10.
📋 What You'll Learn
Create a for loop that iterates from 1 to 10 inclusive
Use an if statement to check if the current number is even
Use the continue statement to skip even numbers
Print only the odd numbers
💡 Why This Matters
🌍 Real World
Skipping unwanted data or conditions is common in programs, like ignoring invalid inputs or filtering lists.
💼 Career
Understanding control flow with <code>continue</code> helps in writing clean and efficient loops, a key skill for software developers.
Progress0 / 4 steps
1
Create a for loop from 1 to 10
Write a for loop with an integer variable i that starts at 1 and runs while i is less than or equal to 10, increasing i by 1 each time.
Java
Need a hint?

Use for (int i = 1; i <= 10; i++) to loop from 1 to 10.

2
Add an if statement to check for even numbers
Inside the for loop, write an if statement that checks if i % 2 == 0 to find even numbers.
Java
Need a hint?

Use if (i % 2 == 0) to check if a number is even.

3
Use continue to skip even numbers
Inside the if block, write the continue statement to skip the rest of the loop when i is even.
Java
Need a hint?

Use continue; inside the if block to skip even numbers.

4
Print only the odd numbers
After the if block, write System.out.println(i); to print the current number i if it is odd.
Java
Need a hint?

Use System.out.println(i); to print the odd numbers.