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

Lars Segelke
Lars Segelke
3,049 Points

Whats wrong?

I get this error, but I don´t know what is wrong.

Program.cs(11,23): error CS1525: Unexpected symbol i', expecting.' Program.cs(11,44): error CS1525: Unexpected symbol )', expecting;' or `}' Compilation failed: 2 error(s), 0 warnings

It says The "i" in the ReadLine is wrong, but that is not possible. Also it says The ")" is wrong, but a ";" or a "}" doesn´t make sense :(

Program.cs
using System;

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

            var times = Console.ReadLine();

            while (int i = 0; i < times; i++)
            {
                Console.WriteLine("Yay!");   
            }
        }
    }
}

1 Answer

James Churchill
STAFF
James Churchill
Treehouse Teacher

Lars,

Looking at loop syntax, it looks like you're trying to use a for loop, but you're using the while keyword instead of the for keyword. Replacingwhilewithforwill resolve your current error. But then you'll get a new compiler error because you're trying to compare the return value from theReadLine` method, which is a string, to an integer.

If you wanted to use a while loop, you could rewrite your code like this:

using System;

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

            var times = int.Parse(Console.ReadLine());
            int i = 0;

            while (i < times)
            {
                Console.WriteLine("Yay!");
                i++;
            }
        }
    }
}

Thanks ~James