Commodore 64 BASIC中的多线功能

use*_*569 6 basic function c64 multiline commodore

所以,我想在Commodore 64 BASIC中编写更大的函数.到目前为止,从我从其他来源(例如各种C64 wiki,以及C64本身的用户手册)看到的,函数定义只能是一行.也就是说,我似乎无法在BASIC中找到括号中的类似构造/其他语言用于描述代码块的其他内容.

有谁知道我如何在BASIC中编写多行代码块?

单行功能示例:

10 def fn X(n) = n + 1
20 print fn X(5) rem Correctly called function. This will output 6
Run Code Online (Sandbox Code Playgroud)

但我做不了类似的事情:

10 def fn X(n) = 
20 n = n + 1
30 print n
40 rem I'd like the definition of function X to end at line 30 above 
50 fn X(5) rem Produces syntax error on line 40
Run Code Online (Sandbox Code Playgroud)

感谢您的时间!

Fen*_*ric 7

可悲的是,C64 BASIC不支持更复杂的功能.

但它支持更复杂的子程序,这就是你想要的.

10 rem you can set up n in advance here
20 n = 23
30 gosub 50
40 rem n is now 24
50 rem start of subroutine; this line is not needed, it's just here for clarity
60 n=n+1
70 print n
80 return
90 rem now you can call the subroutine on line 50 and it'll return at line 80
Run Code Online (Sandbox Code Playgroud)

不幸的是,在C64 BASIC中将参数传递给子程序并从中返回值不是形式化的结构,所以你只需要处理如上所示的普通变量.