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

John Drexler
John Drexler
4,806 Points

Compiler is saying that "while" is unexpected... not sure why

won't compile

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();
            var target = int.Parse(entry);
            var counter = 0

            while (counter < target) {
                counter += 1;
                Console.WriteLine("Yay!");
        }
    }
}

2 Answers

Briain Corroon
Briain Corroon
13,689 Points

Also missing a semi-colon after "var counter = 0"

John Weber
John Weber
6,273 Points

I had trouble with this too and I found that every single person on the forums who had solved it was using a 'for' statement, not a 'while' loop.

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