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# C# Basics (Retired) Perfect Final

Loop

Im stuck, anyone help? :)

using System;

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

            }
        }
    }
}

1 Answer

Steven Parker
Steven Parker
220,450 Points

First, you want the number of times to repeat as int, but Console.ReadLine() returns a string. So you need a way to convert the type, such as this:

            int number = int.Parse(Console.ReadLine());

Then, you need to control how many times you loop using that number. There are a few ways to do this, but one simple one is this:

            while(number-- > 0) 

Then finally, inside the loop, you need to write out "Yay!":

               Console.Write("Yay!");

If you have trouble with the remaining steps of the challenge, you might want to review some of the videos.