VBdotnet2005
asked on
new to C# - exit while
I am new to C#. This is a sample. How can I exit while if 'q' ? Break below in C#, it exit "if" only. If 'q' I need to exit from while loop .
...
while (true)
{
if (line_tmp == "q")
{
break;
}
else
{
Console.WriteLine("There is test");
}
}
...
...
while (true)
{
if (line_tmp == "q")
{
break;
}
else
{
Console.WriteLine("There is test");
}
}
...
Replace break; with return;
...or initialize the variable and change the conditional check:
line_tmp = "";
while (line_tmp != "q")
{
}
line_tmp = "";
while (line_tmp != "q")
{
}
it exit "if" onlybreak has no effect on if blocks--it is only applicable for loops and switch statements. Why do you think it is exiting the if only?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I wonder if I might be humored in getting an answer to: what is different about the code posted in the selected "solution" and the original post? I wish all my answers were that easy.