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 trialJohn Krueger
1,996 PointsLoop won't break.
Trying to make program that prints "Yay!" to console as many times as user enters into the console. My program will start printing "Yay!" but will not stop. Don't know why my loop does not break.
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
Console.Write("Enter the number of times to print \"Yay!\": ");
int entry = Console.Read();
int i = 1;
while (entry >=1)
{
Console.WriteLine("Yay!");
i += 1;
if (i > entry)
{
break;
}
else
{
continue;
}
}
}
}
}
1 Answer
Steven Parker
231,248 PointsYou may be using the wrong input function.
The Console.Read function returns the character code (not the value represented) of a single character.
You might want to use a different function that would read the entire input as a string, and then use another one to convert the string into the value it represents.
John Krueger
1,996 PointsJohn Krueger
1,996 Pointsthnak you that helps.