E01070: 'break' does not exist in EK9 - use stream pipelines with 'head' or guards
What went wrong
The 'break' keyword does not exist in EK9.
Worked examples
Compilable examples demonstrating this error and the correct fix:
Rationale
EK9 excludes 'break' based on 50+ years of production bug evidence:
- Dijkstra (1968): "Go To Statement Considered Harmful" - break is a restricted jump out of the structured flow
- In nested loops a break exits only the innermost loop; a misplaced one compiles and exits the wrong loop
- A break omitted from a switch case falls through silently (CERT C MSC17-C, CWE-484); the Linux kernel's 2019 audit for -Wimplicit-fallthrough found and fixed a number of them
How to fix it
Replace loop + break with stream pipelines using 'head' to take first N items, or use guards to process optional results.
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)
https://ek9.io/streamsAndPipelines.html https://ek9.io/forAI.json#$.excludedFeatures.features[?(@.keyword=="break")]
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E01070: 'break' does not exist in EK9 - use stream pipelines with 'head' or guards
#!ek9 defines module error.e01070.bad defines function firstLongWord() -> words as List of String <- found as String: String() longWordLength <- 5 for word in words if length word > longWordLength found: word break
Fixed: Keep the first match with :=? (assign only while unset) instead of breaking out
#!ek9 defines module error.e01070.good.fix defines function firstLongWord() -> words as List of String <- found as String: String() longWordLength <- 5 for word in words if length word > longWordLength found :=? word
Fixed: Stop pulling items with head instead of breaking out
#!ek9 defines module error.e01070.good defines function isLong() as pure -> word as String <- long as Boolean? longWordLength <- 5 long: length word > longWordLength firstLongWord() -> words as List of String <- found as List of String: List() cat words | filter by isLong | head 1 > found
Fixed: Put the stopping condition in the loop condition
#!ek9 defines module error.e01070.good.while defines function countUntilLimit() -> limit as Integer <- counter as Integer: 0 while counter < limit counter++
Questions and answers
These Q&A entries show E01070 and its fix:
- Q63: How does switch/case work in EK9?
- Q64: How do I write a for loop over a range of numbers?
- Q65: How do I use a for loop to iterate over a collection?
- Q68: Can switch return a value (switch as expression)?
- Q69: How do I match multiple values in one case?
- Q70: How do I use comparison operators in switch cases?
- Q71: How do pattern matching and regex work in switch?
- Q72: What are given/when — alternative switch keywords?
- Q73: How does exhaustive enum switch work?
- Q76: How do guard variables work in for loops?
- Q80: Can a for-range loop return a value (for-range as expression)?
- Q81: Can while and do-while loops return values (loop expressions)?
- Q83: Which control flow constructs can be used as expressions in EK9?
- Q144: Why doesn't EK9 have break, continue, or return statements?
- Q145: How do I exit a loop early or skip iterations in EK9?
- Q147: Why doesn't EK9 have switch fallthrough and how do I group cases?
- Q148: How do I migrate complex control flow from Java or Python to EK9?
- Q275: Why does AI use break and continue in EK9?
- Q282: How do I exit a nested loop without break or labels?
- Q283: How do I implement retry logic without break?
- Q284: How do I find the first match and stop searching without break?
- Q287: How do I process items until a condition is met without break?
- Q288: How do I convert break-based loops from Java or Python to EK9?
- Q979: How do I sort a stream and take the top N items in EK9?
- Q1239: Convert me a Java for-loop with break (find the first item over a threshold) into the equivalent EK9 stream pipeline.
- Q1267: How do I find the first matching item in a list without break or return in EK9?