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 Final

James King
James King
3,670 Points

I'm stuck, once again

I'm using my "Fitness Frog" syntax as a guide but still can't seem to figure out why I'm getting the

CS0139: No enclosing loop out of which to break or continue

error.

Please help?

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the number of times to print \"Yay!\": ");
            var e = Console.ReadLine();
            var times = int.Parse(e);

            if (times == 0)
            {
                Console.WriteLine("No value entered.");
                continue;
            }
            else if (times >= 1)
            {
                Console.WriteLine("Yay!");            
            }
            else
            {
            }
        }
    }
}

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi James,

Disclaimer: I've never written a line of C# in my life.

To solve the error you're seeing:

continue is a keyword used to break out of a loop, like a for loop. You're not inside a loop which is why continue is throwing an error. You're inside an if, else statement, so if the condition is met, "no value entered" will be written to the console, and then the program will move on past the else statements. There's no need to explicitly tell the program to skip those (I assume that's what you were trying to do with continue). So to solve this, simply remove the continue line.

To solve the challenge (part 1)

You need a for loop if the user gave you a number. Let's say they gave you 5. You'll have to print out "Yay!" five times. If you remember for loops (I just googled them :), the syntax goes like this:

for (int i = 0; i < 5; i++) {
    Console.WriteLine("Yay!")
}

You don't want to hard code in a 5, of course - use the number given by the user.

Let me know if you have trouble taking it from here!

Cheers :beers:

-Greg