I have a while loop and inside this while loop I have a foreach loop.
Here I learned how to skip the currently interaction on a loop by using Continue; Return; Break. But I need to leave the while loop when i’m inside the foreach loop is that possible ?
I’m on a interaction inside of the foreach loop and I want to leave the foreach and go to the next interaction of the while. How May I do that ?
Like so:
while (!reader.EndOfStream) //COMEÇO DO WHILE
{
///Some Codes
foreach(string s in checkedlistbox1.items)
{
switch(s)
{
case "1":
if( 1 > 0)
{
///HERE I WANT TO GO TO THE NEXT INTERACTION OF THE WHILE
///When I use CONTINUE; HERE, I GO TO THE NEXT INTERACTION OF THE FOREACH. BUT I NEED TO GO TO THE NEXT OF THE WHILE.
}
}
}
}
Here’s what I want do to:
I’m reading a file.txt line by line, and writing a new one with these values and some others things… Some of these values may be required (seted by user), if a required fieldis empty, so I do nothing, and go to the next while interaction…
You need to break from the switch and then from the foreach, whilst having a variable set.
You can then check that variable to see whether you should
continueto the nextwhileiteration.Do it like this:
Example of this flow working
Outputs: