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#

spin
spin
3,205 Points

C# Final: CS1525: Unexpected symbol `}' error

I can't seem to shake this error: CS1525: Unexpected symbol `}'

Any help would be appreciated. Thanks!

using System;

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

                if(entry.ToLower() == "quit")
                {
                    break;
                }

                try
                {   
                    var repeat = int.Parse(entry);
                    var x = 0; 

                    if(repeat <= 0)
                    {
                         Console.WriteLine("Enter a Positive Number");
                         continue;
                    }
                    for(x < repeat; x++)
                    {
                        Console.WriteLine("Yay!");  
                    }
                }                                            
                catch(FormatException)
               {
                 Console.Write("Enter a Positive Number");
                 continue;
               }

            }
        }
    }
}
Joel Brennan
Joel Brennan
18,300 Points

Hi,

The 'for' loop doesn't look quite right to me.

Shouldn't it be something like:

for (int x = 0; x < repeat; x++)
{
    Console.WriteLine("Yay!");
}

Missing a semi-colon after your x variable?

1 Answer

Steven Parker
Steven Parker
216,133 Points

A for loop need 3 clauses, enclosed in parentheses and separated by semicolons, but the one here only has two.

I noticed a few other issues as well:

  • the error messages are not correct and/or are not exactly as the instructions asked
  • there is an extra loop that prevents the program from ending until "quit" is entered

A program conforming to the challenge instructions will prompt and accept input only one time, and will output a number of "Yay!"s or an error message depending on the validity of the input, and then it will end.