I have tried return from outer function:
fun s(x : Int) : Int{
var sn = 0;
fun s1()
{
sn += 1
if( sn > 3)
return@s 3
}
for (i in 1..x)
s1()
return sn
}
But I have error: Error:(7, 13) Kotlin: 'return' is not allowed here
Why?
I don’t see big difference from example at http://confluence.jetbrains.com/display/Kotlin/Functions:
fun
reachable
(
from
:
Vertex
,
to
:
Vertex
)
:
Boolean
{
val
visited
=
HashSet
<
Vertex
>
(
)
fun
dfs
(
current
:
Vertex
)
{
// here we return from the outer function:
if
(
current
==
to
)
return
@reachable
true
// And here – from local function:
if
(
!
visited
.
add
(
current
)
)
return
for
(
v
in
current
.
neighbors
)
dfs
(
v
)
}
dfs
(
from
)
return
false
// if dfs() did not return true already
}