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

Kevin Gent
Kevin Gent
1,028 Points

C# Basics: Final Challenge 2 of 3 continue statement problem

error CS0139 Something is wrong with my continue statement. To my limited knowledge my continue statement should be putting me back to the top of my code where it asks the user to enter the number of "Yays!". What am I doing wrong with my continue statement?

Kevin Gent
Kevin Gent
1,028 Points

Is it not showing my code? I checked the include code box? Well if not seen here is my code:

       Console.Write("Enter the number of times to print \"Yay!\": ");

        try
        {

            int counter = 0;
            String times = Console.ReadLine();
            int totals = int.Parse(times);
            while (counter < totals)
            {
                Console.Write("\"Yay!\"! ");
                counter += 1;
            }
        }
        catch
        {
            Console.WriteLine("You must enter a whole number");
            continue;
        }

        Console.ReadLine();

1 Answer

Kevin Gent
Kevin Gent
1,028 Points

Ooop found it out. continue statments go back to loops. All I had to do was add another while and put it on the outside of everything. Here is my finalized code that works:

            while (true)
            {
            Console.Write("Enter the number of times to print \"Yay!\": ");

            try
            {

                int counter = 0;
                String times = Console.ReadLine();
                int totals = int.Parse(times);
                while (counter < totals)
                {
                    Console.Write("\"Yay!\"! ");
                    counter += 1;
                }
            }
            catch
            {
                Console.WriteLine("You must enter a whole number");
                continue;
            }