• bss03@infosec.pub
      link
      fedilink
      English
      arrow-up
      4
      ·
      5 days ago

      Java doesn’t allow goto, but specifically does have labels for labeled break/continue to support the multi-loop exiting case.

      I imagine these two “structures” will always be implemented in C source through disciplined use of goto.

      • Gladaed@feddit.org
        link
        fedilink
        arrow-up
        4
        arrow-down
        1
        ·
        5 days ago

        It’s literally the only way to do this. Other ways include checking of loads of bools. That’s slow.

        • bss03@infosec.pub
          link
          fedilink
          English
          arrow-up
          3
          ·
          5 days ago

          In C maybe. In language that support proper recursion schemes, the apomorphism models the early-exit loop.

  • Frezik@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    9
    ·
    5 days ago

    IIRC, this is because gcc optimizes goto very well, or at least it did back in the day. It also is a genuinely workable solution for error handling in C.

    Consider if you need to setup three things, do something with them, and then tear them down in reverse order. If there’s an error on the second thing, you want to jump right to the part where you tear down the first thing. Using goto tends to make cleaner code for that in C compared to, say, nested conditionals.