Useful alternative control structures?

后端 未结 28 982
礼貌的吻别
礼貌的吻别 2021-01-30 02:20

Sometimes when I am programming, I find that some particular control structure would be very useful to me, but is not directly available in my programming language. I think my

28条回答
  •  故里飘歌
    2021-01-30 03:12

    {
        foo();
    } split_while( condition ) {
        bar();
    }
    

    You can accomplish that pretty easily using a regular while:

    while (true) {
        foo();
        if (!condition) break;
        bar();
    }
    

    I do that pretty frequently now that I got over my irrational distaste for break.

提交回复
热议问题