When is a do-while appropriate?

后端 未结 13 1783
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条回答
  •  Happy的楠姐
    2020-11-30 09:28

    I've long held that do-while is not used in C-based languages as much as it should be because the reuse of the "while" keyword is awkward and confusing. Pascal's repeat-until does not share any keywords with its while-begin-end structure.

    I'd love to analyze a big heap of code someday and see if do-while is underrepresented in C code compared to similar constructs in other languages.

提交回复
热议问题