E01076: 'goto' does not exist in EK9 - use structured control flow

Category: E01xxx Parsing and excluded constructs · Reported in phase: SYMBOL_DEFINITION · Classification: GOTO_NOT_SUPPORTED · All error codes

What went wrong

The 'goto' statement does not exist in EK9.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 786 (Which keywords from other languages are excluded from E...)

Rationale

EK9 excludes 'goto' based on critical evidence:

  • Dijkstra (1968): "Go To Statement Considered Harmful" - seminal paper
  • Apple SSL Bug (2014): 'goto fail' created unreachable code, bypassed SSL validation
  • goto is widely regarded as producing hard-to-follow "spaghetti" code
  • Structured programming has been the norm for more than 50 years

How to fix it

Use structured control flow: try/catch/finally, guards, or stream pipelines. EK9's scope-based resource management eliminates most goto use cases.

See also

  • E01070: 'break' not supported (use stream pipelines with 'head')
  • E01071: 'continue' not supported (use stream pipelines with 'filter')
  • E01072: 'return' not supported (use return declarations)
  • E01073: 'null' not supported (use tri-state semantics)
  • E01074: semicolons not needed (indentation-based syntax)
  • E01075: 'new' not supported (use TypeName() directly)

https://ek9.io/flowControl.html#excluded-features https://ek9.io/forAI.json#$.excludedFeatures.features[?(@.keyword=="goto")]

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E01076: 'goto' does not exist in EK9 - use structured control flow

#!ek9
defines module error.e01076.bad

  defines constant
    MaximumAttempts <- 3

  defines function

    process()
      -> attempts as Integer
      if attempts > MaximumAttempts
        goto cleanup

Fixed: Use structured control flow: the clean-up goes in a finally block, which always runs

#!ek9
defines module error.e01076.good

  defines constant
    MaximumAttempts <- 3

  defines function

    attempt()
      -> attempts as Integer
      <- rtn as String: attempts > MaximumAttempts <- "gave up" else "tried"

    cleanup()
      stdout <- Stdout()
      stdout.println("cleaned up")

    process()
      -> attempts as Integer
      stdout <- Stdout()
      try
        stdout.println(attempt(attempts))
      finally
        cleanup()