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

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

I seem to be stuck with this project. the error states i have no way to exit the loop but It seems as if it can. Any help would be appreciated.

Ken Alger
Ken Alger
Treehouse Teacher

Robbie;

Welcome to Treehouse!

Can you post the code you are using please?

Happy coding.
Ken

using System;

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

            int i = 0;
            if (i > timesToPrint)
              {
                System.Console.Write("Yay!");
                i++;
              }
            else
              break;


    }
}

}

2 Answers

I actually figured it out. Was trying to use the break keyword outside of a loop.

/////////////////////////////////////////////////////////////// Same Problem in 15 line can't solve maybe someone could help? /////////////////////////////////////////////////////////////// using System;

namespace Treehouse.CodeChallenges { class Program { static void Main() { int nTimes; string times = Console.ReadLine(); try { nTimes = int.Parse(times); } catch(FormatException){ Console.WriteLine("You must enter a whole number."); continue; }
while (nTimes >= 0) { Console.Write("Enter the number of times to print \"Yay!\": "); nTimes--; } } } }