string s = Console.ReadLine();
while(s != null)
{
// do something
// ....
s = Console.ReadLine();
}
The code above is to get the input, verify it, process it and then input again, but obviously, s = Console.ReadLine(); is code duplication.
What tricks are there to avoid the duplication?
depending on language, you can often do something like this:
while (s = Console.ReadLine())
{
...
}
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