do {…} while(false)

前端 未结 25 2550
小鲜肉
小鲜肉 2020-11-28 03:29

I was looking at some code by an individual and noticed he seems to have a pattern in his functions:

 function()
{
 

        
25条回答
  •  青春惊慌失措
    2020-11-28 04:07

    This is just a perversion of while to get the sematics of goto tidy-up without using the word goto.

    It's bad form because when you use other loops inside the outer while the breaks become ambiguous to the reader. "Is this supposed to goto exit? or is this intended only to break out of the inner loop?"

提交回复
热议问题