When is a do-while appropriate?

后端 未结 13 1769
Happy的楠姐
Happy的楠姐 2020-11-30 09:15

When is a do-while the better choice over other types of loops? What are some common scenarios where its better than others?

I understand the function of a do-while,

13条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 09:38

    Another exception when you are doing something recursive, like the following with reading inner exceptions:

    catch(Exception exc)
    {
        Exception currentException = exc;
        do
        {
            Console.WriteLine(string.Format("{0}: {1}", currentException.GetType().Name, currentException.Message));
        } while((currentException = currentException.InnerException) != null);
    }
    

提交回复
热议问题