Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: break and continue | Løkker
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
C#-Grunnleggende

bookChallenge: break and continue

Oppgave

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).

Løsning

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 11
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

close

bookChallenge: break and continue

Sveip for å vise menyen

Oppgave

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).

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 11
single

single

some-alt