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#

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
229,670 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.