BasicsTutorial/Sub-routines

Last-modified: 2008-03-10 (月) 14:57:33

Sub-routines

サブルーチン

Remember labels and the GOTO command?
ラベルとGOTO命令を覚えている?
Well subroutines are an extension of that.
よく、サブルーチンはそれの拡張である。

gosub _getInput
gosub _printStuff
wait key
end
_getInput:
  input "What's your name? ",name$
  input "How old are you? ",age
return
_printStuff:
  print "You are ",age," years old ",name$,"."
return

The new command GOSUB is almost the same as GOTO, it makes the computer jump to the specified label, it’s just that once it has it looks out for the RETURN command.
新しい命令GOSUBは GOTOとほとんど同じである、それはコンピュータを指定されたラベルへジャンプさせる、それがRETURN命令に気をつけることはちょうどそれが持つその一度である。
When it finds it, it jumps right back to the label again and continues from where it left off.
それがそれを見つけるとき、それは再びラベルへ正にジャンプして、それが離れて去ったところから続ける。

The GOSUB command is useful for sectioning off parts of your code to make it neater.
GOSUB命令は、それをよりきちんとしているようにするためにあなたのコードの外れた部分を区分することに役立つ。
This means that you can re-arrange the sub-routines, as the sections are known as, without muddling up the code order.
セクションが知られているように、これはあなたがサブルーチンを再編成することができることを意味する、コードの順番をごちゃまぜにすることなく。
If you want to re-arrange the code order you just have to move one line.
あなたがコードの順番を再編成したいならば、あなたはちょうど一行を動かさなければならない。
A lot neater than one big block of code.
大きい1ブロックのコードよりきちんとした多く。

Just remember that you should use the END command to end the program, because if the computer runs into a RETURN command without a GOSUB first it won’t compile.
あなたがプログラムを終えるためにEND命令を使わなければならないのをコンピュータがGOSUBなしでそれが編集しない 最初をRETURN命令に陥らせるので、ちょっと思い出しなさい。

I have also decided to start the labels with an underscore this time.
私は、今度はラベル名をアンダーラインで始めることにも決めた。
This does nothing technically but allows you to pick out them easily among variables and commands.
これは技術的に何もしなくて、変数と命令の間で容易にそれらを見分けることができる。

Summary of Commands

命令の概要

· GOSUB label - Jumps to the label specified and looks for a RETURN command so that it can jump back to the GOSUB command.
GOSUBラベル - 指定されるラベルへジャンプして、それがGOSUB命令へ戻る為にジャンプすることができるように、RETURN命令を探す。

· RETURN - Makes the computer jump back to the last GOSUB command.
RETURN - コンピュータを最後のGOSUB命令へジャンプさせる。