-1

Consider the following loop:

While Console.In.Peek() >= 0
    Console.WriteLine(Console.ReadLine())
End While

It works as expected (i.e. echos the input) when the input is re-directed from a file. However, when the lines are typed in console, the program exits after the first line. Why does this happen and how can it be fixed? In other words, what should I write in the loop condition so that it exits only when Ctrl+Z is typed?

AlwaysLearning
  • 7,257
  • 4
  • 33
  • 68

1 Answers1

0
    While (Console.ReadLine IsNot Nothing)
        Console.WriteLine(Console.ReadLine())
    End While

You have to hit enter after Ctrl+Z for this to work. Ctrl+Z returns null

https://msdn.microsoft.com/en-us/library/system.console.readline(v=vs.110).aspx

p3tch
  • 1,414
  • 13
  • 29