Is goto ok for breaking out of nested loops?

后端 未结 10 1839
忘掉有多难
忘掉有多难 2021-01-18 04:33

JavaScript supports a goto like syntax for breaking out of nested loops. It\'s not a great idea in general, but it\'s considered acceptable practice. C# does not directly

10条回答
  •  情歌与酒
    2021-01-18 05:21

    I would personally try to avoid using goto here by simply putting the loop into a different method - while you can't easily break out of a particular level of loop, you can easily return from a method at any point.

    In my experience this approach has usually led to simpler and more readable code with shorter methods (doing one particular job) in general.

提交回复
热议问题