Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: break and continue | Section
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
C# Basics
Sectionย 1. Chapterย 44
single

single

bookChallenge: break and continue

Swipe to show menu

Task

Swipe to start coding

In this task, you will practice using break and continue statements in a for loop with a simple scenario.

  • Initialize a variable total to 0 to store the sum of processed numbers.
  • Use a for loop to count numbers from 1 up to 10.
  • Inside the loop:
    • Use i % 4 == 0 to check if a number is divisible by 4.
    • Use continue to skip numbers divisible by 4.
    • Use break to stop the loop when a number is greater than 8.
    • Update total with total = total + i.
  • Print each processed number with Console.WriteLine("Number: " + i).
  • Print the final sum with Console.WriteLine("Total sum: " + total).

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Sectionย 1. Chapterย 44
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt