ReadKey() input question [Answered]

{
Console.ReadKey();
points++;
Console.WriteLine(points);

}
while (Console.ReadKey().Key != ConsoleKey.Escape);
{
Console.ReadKey();
points++;
Console.WriteLine(points);

}
while (Console.ReadKey().Key != ConsoleKey.Escape);
This former does the points++ on first press, and every other as shown in picture while the following does it every time.
while (true)
{
ConsoleKey key = Console.ReadKey().Key;
if (key == ConsoleKey.Escape)
break;

score++;
Console.WriteLine(score);
}
while (true)
{
ConsoleKey key = Console.ReadKey().Key;
if (key == ConsoleKey.Escape)
break;

score++;
Console.WriteLine(score);
}
Why is that?
3 Replies
TheBoxyBear
TheBoxyBear2y ago
In the first one, you're reading the key twice Once in the loop and the other to check if the loop should run again
BigggMoustache
thanks lol
Accord
Accord2y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server
More Posts