注册 登录
编程论坛 Python论坛

goto 只能用在def 裡嗎?

Z89 发布于 2022-06-23 16:16, 626 次点击
goto 只能用在def 裡嗎?沒用在def就出錯



程序代码:
from goto import with_goto

@with_goto
def range(start, stop):
    i = start
    result = []

    label .begin
    if i == stop:
        goto .end

    result.append(i)
    i += 1
    goto .begin

    label .end
    return result

a= range(0,10)

print(a)


程序代码:


from goto import with_goto

@with_goto

i = 0
result = []
label .begin
if i == 10:
   goto .end
result.append(i)
i += 1
goto .begin
label .end
print(result)
1 回复
#2
wp2319572022-06-25 12:39
回复 楼主 Z89
很明显,几乎所有语言都排斥goto
1