C #: While loops with condition at the end

In VB, I can write a loop that always runs at least once. For instance:

Do [code] Loop While [condition] 

Is there any way to do this in C #?

+4
source share
4 answers

Sure:

 do { ... } while (condition); 

See do (C# Reference) .

+12
source
 do { // code } while (condition) 
+13
source

As an alternative

 bool finished = false ; while ( !finished ) { // do something finished = // evaluate a new foo } 

I have never been a big fan of do / while

-3
source
  TopOfLoop: // ... if (condition) { goto TopOfLoop; } 

No career is complete without at least one goto .

-5
source

Source: https://habr.com/ru/post/1335616/


All Articles