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

Roimant Alvarez Ramirez
Roimant Alvarez Ramirez
1,161 Points

Why is it Saying Bummer? Sometimes it saw to slow.

using System;

namespace Treehouse.CodeChallenges { class Program { static void Main() { Console.Write("Enter the number of times to print \"Yay!\": "); string x = Console.ReadLine(); while (true) {
try {
int y = int.Parse(x); int z = 1; if(z <= y) {
Console.WriteLine("Yay!"); z++;
}

                else if(z <= 0)
                {
                    Console.WriteLine("You must enter a positive number.");
                    continue;
                }
            }
            catch(FormatException)
            {
                Console.WriteLine("You must enter a whole number");
                continue;
            }
        }
    }
}

}

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the number of times to print \"Yay!\": ");
            string x = Console.ReadLine();
            while (true)
            {                
                try
                {                
                    int y = int.Parse(x);
                    int z = 1;
                    if(z <= y)
                    {    
                        Console.WriteLine("Yay!");
                        z++;                        
                    }

                    else if(z <= 0)
                    {
                        Console.WriteLine("You must enter a positive number.");
                        continue;
                    }
                }
                catch(FormatException)
                {
                    Console.WriteLine("You must enter a whole number");
                    continue;
                }
            }
        }
    }
}

1 Answer

Taras Metelskii
Taras Metelskii
4,167 Points

Looks like infinite loops. There is no escape from while loop.