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!

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

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!