My code simply Creates a refrence variable of StreamReader object that reads a TextFile, After that using a while loop to retrive data from the TextFile.
- StreamReader sr = new StreamReader("File.txt");
- string line = "";
- while (line != null)
- {
- line = sr.ReadLine();
- Console.WriteLine(line);
- }
So, forgive my innocent question : The condition in the While loop is TRUE, so why it doesn't return an infinite loop ? instead it retrives the data from "File.txt" then it breaks the loop?
All what I know as a newbie programmer is that if the condition of the loop is TRUE keep it going until it turns to FALSE then the loop will break; itself.
Could somebody explain the logic behind this scenario please!
Ramesh PalanivelPosted Jan 24, 2018, 2:30 AM
Kal KalPosted Jan 24, 2018, 6:42 AM