Is using goto a legitimate way to break out of two loops?

前端 未结 6 868
悲哀的现实
悲哀的现实 2021-01-01 16:05

I am solving problem 9 on the Project Euler. In my solution I use a "goto" statement to break out of two for loops. The Problem is the following:

6条回答
  •  感动是毒
    2021-01-01 16:11

    I can't think of a better alternative. But one alternative not using goto would be modifying the first for-loop:

    for (a = 1; a

    Then break out of the second for-loop. That will work assuming the result will never be -1 after the second for-loop has been broken by break.

提交回复
热议问题