Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: break and continue | Boucles
Bases de C#

bookChallenge: break and continue

Tâche

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

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 11
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

close

bookChallenge: break and continue

Glissez pour afficher le menu

Tâche

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 desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 11
single

single

some-alt