Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Desafío: Break y Continue | Bucles
Fundamentos de C#

bookDesafío: Break y Continue

There is a for loop without a default ending condition.

Inside the loop, skip all the even iterations and in case of odd iterations increment the value of oddNumbers. Stop the loop as soon as the value of oddNumbers equals 27. Use break and continue statements for this purpose.

main.cs

main.cs

copy
12345678910111213141516171819202122232425
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { int oddNumbers = 0; for (int i = 0; ; i++) { if (___) { ___ } ___++; Console.WriteLine(i); if (___) { ___ } } } } }

A number x is even if it satisfies the condition x % 2 == 0.

main.cs

main.cs

copy
12345678910111213141516171819202122232425
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { int oddNumbers = 0; for (int i = 0; ; i++) { if (i % 2 == 0) { continue; } oddNumbers++; Console.WriteLine(i); if (oddNumbers == 27) { break; } } } } }

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 8

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Suggested prompts:

Can you show me an example of how the loop should look in code?

What programming language should I use for this task?

Can you explain how the `break` and `continue` statements work in this context?

bookDesafío: Break y Continue

Desliza para mostrar el menú

There is a for loop without a default ending condition.

Inside the loop, skip all the even iterations and in case of odd iterations increment the value of oddNumbers. Stop the loop as soon as the value of oddNumbers equals 27. Use break and continue statements for this purpose.

main.cs

main.cs

copy
12345678910111213141516171819202122232425
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { int oddNumbers = 0; for (int i = 0; ; i++) { if (___) { ___ } ___++; Console.WriteLine(i); if (___) { ___ } } } } }

A number x is even if it satisfies the condition x % 2 == 0.

main.cs

main.cs

copy
12345678910111213141516171819202122232425
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { int oddNumbers = 0; for (int i = 0; ; i++) { if (i % 2 == 0) { continue; } oddNumbers++; Console.WriteLine(i); if (oddNumbers == 27) { break; } } } } }

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 8
some-alt