© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
11 replies
krixsick

❔ C# Error with a while loop (course work)

Hello! This i my code currently. The main issue that arises is that the code will still print out -9 for some reason. I'm not too sure on why it does that because I have a module function that checks whether a number is divisible by 3 or not. I was told not to change the "if (i == 11).
{
Console.WriteLine(" FINAL BREAK REACHED! This should not happen!");
break;
}
Console.WriteLine(i++);"

part but to instead add code inside the while function to do that. My goal is for the loop should skip all divisible by 3 values and stop running when i = 10. So far it achieves this result for the other numbers expect for -9


namespace Challenge_LoopsOneAverage
{
internal class Program
{
static void Main(string[] args)
{
int i = -10;

while (true)
{

if (i % 3 == 0)
{
i++;
continue;
}
else if (i == 10)
{
break;
}
Console.WriteLine(i++);
if (i == 11)
{
Console.WriteLine(" FINAL BREAK REACHED! This should not happen!");
break;
}
Console.WriteLine(i++);
}
}
}
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

c# addition and subtraction with while loop
C#CC# / help
16mo ago
C# course
C#CC# / help
2y ago
while-loop
C#CC# / help
4y ago
❔ C sharp Loop
C#CC# / help
4y ago