Challenge: break and 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
12345678910111213141516171819202122232425using 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
12345678910111213141516171819202122232425using 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; } } } } }
Tack för dina kommentarer!
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Awesome!
Completion rate improved to 1.59
Challenge: break and continue
Svep för att visa menyn
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
12345678910111213141516171819202122232425using 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
12345678910111213141516171819202122232425using 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; } } } } }
Tack för dina kommentarer!