COMMUNITY: How to properly ask a question on Forums
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forum guidelines
Kal Kal
1.6k
7
152
What is the logic behind while loop behavior in this case?
Jan 24 2018 2:20 AM
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
Answers (
2
)
How to hide savefiledialog box c#
once condition met, send email automatically
"