Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Basics (Retired) Perfect Final

Ivan Dario Cuervo Ariza
Ivan Dario Cuervo Ariza
887 Points

Stuck with compiler error

Getting error: "Program.cs(25,19): error CS0139: No enclosing loop out of which to break or continue Compilation failed: 1 error(s), 0 warnings"

Program.cs
using System;

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

            string entry = System.Console.ReadLine();

            try 
                {
                   int times = int.Parse(entry);
                   var count = 1;
                    while (count<=times)
                    {
                    Console.Write("Yay!");
                    count++;    
                    }
                }

            catch(FormatException)
                {
                  Console.WriteLine("You must enter a whole number.");
                  continue;

                }

        }
    }
}

2 Answers

Your code is technically functional, but the "continue;" in the catch block is throwing a compiler error.
The "continue" keyword is used to skip the current iteration of a loop, and not to return to a different part of the program. Since a catch block is not a loop, it cannot skip an iteration of a loop and continue looping thereafter. Simply remove the "continue;" and your code should pass the challenge just fine.

Ivan Dario Cuervo Ariza
Ivan Dario Cuervo Ariza
887 Points

Excellent! It worked! Thanks for taking the time to explain!