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

Jason Martin
PLUS
Jason Martin
Courses Plus Student 9,316 Points

Final Task 2 "try / catch" structure

I tried following the tips in other posts, but the code below says that there is no where to break; or continue;

What is wrong?

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the number of times to print \"Yay!\": ");
            var entry = Console.ReadLine();
            try
            {
              for(var i = 0; i < int.Parse(entry); i++)
                {
                  Console.WriteLine("Yay!");
                }
            }
            catch(FormatException)
            {
              Console.WriteLine("You must enter a whole number.");
              continue;
            }

        }
    }
}

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,624 Points

Hey Jason,

I'm not sure if you've got this figured yet, but if you don't...

I would suggest not using a for loop. If you use a while loop, you don't need to worry about continue or break.

For the 1st part of the challenge, this code will pass. Hopefully it makes sense.

using System;

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

      var entry = System.Console.ReadLine();

      var numberTimes = int.Parse(entry);

      var i = 0;
      while ( i < numberTimes )
      {
        Console.WriteLine("Yay!");

        i += 1;
        }
      }
    }
  }

Keep Coding! :dizzy:

Jason Martin
PLUS
Jason Martin
Courses Plus Student 9,316 Points

Thanks for the help! I had a feeling the for loop was throwing me off...