Currently I am using this code:
using System;
namespace Project
{
class MainClass
{
public static void Main (string[] args)
{
bool key = false;
while (key == false)
{
Console.WriteLine ("Loop");
}
}
}
}
Which works fine, but I wanted to make the loop stop when a key is pressed. I tried this:
using System;
namespace Project
{
class MainClass
{
public static void Main (string[] args)
{
bool key = false;
while (key == false)
{
Console.WriteLine ("Loop");
{
Console.ReadKey (true);
key = true
}
}
}
}
}
But that just continues the loop when a key is pressed. Any solutions?
I suggest using Console.KeyAvailable:
while (!Console.KeyAvailable) {
Console.WriteLine("Loop");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With