wybe
wybe copied to clipboard
Allow for an early return in a proc
Sometimes, the use of an early return is useful.
Perhaps we can add a return
statement that acts like fail
but instead of failing the procedure, terminates the procedure without failing
e.g.
def product(matrix:list(list(int)), ?p:int) {
?p = 1
for ?row in matrix {
for ?i in row {
if { i = 0 :: ?p = 0; return }
!p *= i
}
}
}
I suppose this example could be solved with the use of a generalised break
, taking an optional integer constant, n
argument that breaks n
loops
e.g.
def product(matrix:list(list(int)), ?p:int) {
?p = 1
for ?row in matrix {
for ?i in row {
if { i = 0 ::
?p = 0
break 2
}
!p *= i
}
}
}
Generalised next
makes sense too, then