Which loop to use, for or do/while?

后端 未结 13 977
Happy的楠姐
Happy的楠姐 2021-01-19 23:02

Using C# (or VB.NET) which loop (for loop or do/while loop) should be used when a counter is required?

Does it make a difference if the loop should only iterate a se

13条回答
  •  鱼传尺愫
    2021-01-19 23:39

    Just for completeness, you could also use option D:

    for (int iLoop = 0; Criteria; iLoop++)
    {
       // work here
    }
    

    (where Criteria is "to keep running")

    the condition in a for loop doesn't have to involve iLoop. Unusual, though, but quite cute - only evaluates before work, though.

提交回复
热议问题