0
0
Cprogramming~15 mins

Continue statement - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the Continue Statement in C
📖 Scenario: Imagine you are sorting through a list of numbers and want to skip certain numbers based on a rule, like ignoring even numbers.
🎯 Goal: You will write a C program that uses the continue statement inside a loop to skip printing even numbers from a list.
📋 What You'll Learn
Create an array of integers with specific values
Create a variable to hold the length of the array
Use a for loop to go through the array
Use the continue statement to skip even numbers
Print only the odd numbers
💡 Why This Matters
🌍 Real World
Skipping unwanted data while processing lists or arrays is common in many programs, such as filtering out invalid inputs or ignoring certain cases.
💼 Career
Understanding how to control loops with statements like continue is essential for writing efficient and clear code in software development.
Progress0 / 4 steps
1
Create an integer array
Create an integer array called numbers with these exact values: 2, 5, 8, 11, 14, 17.
C
Need a hint?

Use the syntax int numbers[] = {values}; to create the array.

2
Create a variable for array length
Create an integer variable called length and set it to the number of elements in the numbers array using sizeof(numbers) / sizeof(numbers[0]).
C
Need a hint?

Use sizeof to find the total size of the array and divide by the size of one element.

3
Use a for loop with continue to skip even numbers
Write a for loop using int i = 0; i < length; i++ to go through numbers. Inside the loop, use an if statement to check if numbers[i] is even (use numbers[i] % 2 == 0). If it is even, use the continue statement to skip to the next loop iteration.
C
Need a hint?

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

4
Print only the odd numbers
Inside the for loop, after the continue statement, add a printf statement to print the odd numbers with a space after each number. Use printf("%d ", numbers[i]);. After the loop, print a newline with printf("\n");.
C
Need a hint?

Use printf("%d ", numbers[i]); to print each odd number followed by a space.

Don't forget to print a newline after the loop.