Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Basics (Retired) Perfect break and continue

Matthew Musni
Matthew Musni
610 Points

2nd question of the quiz explanation please thanks

i just dont get why the answer is nothing will be printed out

2 Answers

andren
andren
28,558 Points

Since the loop's condition for running is true it will never end naturally (meaning you would have to use the break keyword to stop it) and since the first line is continue which causes the loop to start over from line 1 it will never end up running the print statement on line 2 within the loop.

In other words the loop will just run the continue line indefinitively.

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Matthew! The code I believe you're referring to is this:

while(true)
{    
    continue;
    Console.WriteLine("Ribbit")
}

Console.WriteLine("Croak");

What we have here is an endless loop. It starts at the while and says while(true). This will always evaluate to true, so it starts running the code inside the curly braces. The continue tells the code to return to the top of the loop at while(true). It never makes it to the "Ribbit" part. it just keeps jumping right back up to the top. This means that it also never makes it out of the loop to the "Croak" part either. Hence, nothing will ever print out.

Hope this helps! :sparkles: