Challenge: break and continue
Tehtävä
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
totalto0to store the sum of processed numbers. - Use a for loop to count numbers from 1 up to 10.
- Inside the loop:
- Use
i % 4 == 0to check if a number is divisible by 4. - Use
continueto skip numbers divisible by 4. - Use
breakto stop the loop when a number is greater than 8. - Update
totalwithtotal = total + i.
- Use
- Print each processed number with
Console.WriteLine("Number: " + i). - Print the final sum with
Console.WriteLine("Total sum: " + total).
Ratkaisu
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 4. Luku 11
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Mahtavaa!
Completion arvosana parantunut arvoon 1.25
Challenge: break and continue
Pyyhkäise näyttääksesi valikon
Tehtävä
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
totalto0to store the sum of processed numbers. - Use a for loop to count numbers from 1 up to 10.
- Inside the loop:
- Use
i % 4 == 0to check if a number is divisible by 4. - Use
continueto skip numbers divisible by 4. - Use
breakto stop the loop when a number is greater than 8. - Update
totalwithtotal = total + i.
- Use
- Print each processed number with
Console.WriteLine("Number: " + i). - Print the final sum with
Console.WriteLine("Total sum: " + total).
Ratkaisu
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 4. Luku 11
single