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

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,858 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...