Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
What is the logic behind while loop behavior in this case?
Kal Kal
Jan 24 2018 2:20 AM
205
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!
Reply
Upload Source Code
Select only zip and rar file.
Post
Reset
Answers (
2
)
How to hide savefiledialog box c#
once condition met, send email automatically