計算機英語:BASIC語言入門

字號:

How to Use BASIC
    Getting Started in BASIC
    The best way to learn the computer language into do, and you will learn much quicker if you dare to make mistakes.Don't worry about breaking the computer by mistyping something. The computer can take care of itself If you have questions about how BASIC will respond to a particular instruction, try it and sec.
    Each instruction has a particular format, or syntax. If you do not follow the correct syntax, BASIC will usually display an error message. You can then reenter the instruction correctly。
    At first, you need to know both to get into BASIC and ho-, N, to get out. Once you have learned some BASIC, you may begin to type. After you type alien the computer will wait for you to type a signal that you arc finished with the line. You give this signal by tapping the [Enter] key.This key is usually a large one located to the right of the alphabetic keyboard. It is similar in purpose and in placement to the carriage [Enter] key on a typewriter.
    As You type, You'll notice a blinking light on the screen that indicates where the next character will appear. This is the cursor. When you press [Enter],the cursor moves to the beginning of the next line.The cursor always lets you know where you are on the screen.
    Let's try using BASIC as a calculator. We do this by using the PRINT statement,
    PRINT 3
    3
    We typed PRINT followed by a space, the digit3,and pressed [Enter].BASIC responded by display-in the digit 3.
    PRINT 2+2
    4
    We typed PRINT followed by a space and the numeric expression 2+2.BASIC evaluated the expressions and displayed the result. Here is another example:
    PRINT 3,2+2
    34
    When we tap [Enter],we tell the BASIC Interpreter to check our command for errors and, if none are found, translate the command into machine language and execute. All that happens at great speed! Let’s try a few more examples.
    We can make BASIC type two values on online by placing a comma between calculations.
    PRINT 1,2,3,4,5
    12345
    PRINT I,2,3,4,5
    12345
    Notice what happened:BASIC divided the display line into print zones.These print zones are commonly spaced columns apart, creating five print zone son an 80-column screen.(The exact number will depend on the dialect.)The comma between the values causes BASIC to skip to the next print zone for each value. By using commas,we can print output in neat columns. The extra spaces between values on the PRINT line, as in the second example, do not affect the spacing of the output。
    Numeric values are displayed with a minus signing front if the value is negative and a space in front if the value is positive.In most dialects they are also followed by a space.
    If you want to print values next to one another, you use the semicolon, which suppresses movement tote next print zone. Here is an example:
    PRINT I;-2;3+3
    1 -26
    Using the semicolon, results are printed next tone another, with the space for the sign in front and a space after.
    The comma and the semicolon are used as delimiters to separate values.Because of this,no commas should be placed in values over 999.To print 12,345we must type PRINT 12345。If we write PRINT12,345,BASIC will interpret it as the two numbers12 and 345。
    In our initial discussions we Novell be printing to the screen.however.the same Information can be printed on the printer if our system has one.In most systems this is done with the LPRINT statement MINT uses the same syntax as PRINT.However, PRINT directs output to the printer instead of the screen.On some systems,simultaneously pressing the[Ctrl] and [Parts] keys or the [Ctrl]。and [P] keys will cause all output that is sent to the screen to be sent to the printer as well.This acts as a toggle.That is, the first [Ctrl] and [Parts] (for example) will turn on the connection between the computer and printer. The next [Citric] and putsch will turn it off. Because dialects vary so widely, we will not describe LPRINT in detail.
    翻譯:
    怎樣使用BASIC語言
    BASIC語言入門
    學(xué)習(xí)計算機語言的方法就是試著編程,且如果你敢于犯錯誤的一話,將學(xué)得更快。不要擔(dān)心敲錯了什么會弄壞計算機。計算機會照顧好自己的。如果你想知道BASIC對一條特定的指令反應(yīng)如何,不妨上機操作試試看。
    每條指令都有特別的格式或語法。如果語法錯誤,BASIC一般將顯示出錯信息。接著可重新鍵入正確的指令。
    首先需要知道的是如何進入和 退出BASIC系統(tǒng)。一旦你學(xué)了一些BASIC語言之后,便可開始鍵入指令。敲完一行后,計算機將等待你鍵入指示程序行結(jié)束的信號。此時,敲回車[Enter]鍵即可。該鍵較大,通常位于字母鍵盤的右邊。它與打字機上的換行回車鍵的功能和位置都相仿。
    有一閃爍亮點提示下一個字符出現(xiàn)的位置。這就是光標(biāo)。敲回車鍵后,光標(biāo)移到下一行的開頭。光標(biāo)總是提示你當(dāng)前在屏幕上所處的位置。
    現(xiàn)在,讓我們試著把BASIC當(dāng) 計算器使用。這需要用到打印語句
    PRINT 3
    3
    我們鍵入“PRINT”,接著是一 個空格和數(shù)字“3”,并按回車 鍵。BASIC的反應(yīng)就是顯示數(shù)字3。
    PRINT 2+2
    4
    我們鍵入“PRINT”和空格及數(shù) 值表達式“2+2”。BASIC將表達式 的值計算出來并顯示結(jié)果。再舉一個例子:
    PRINT 3,2+2
    34
    當(dāng)我們敲回車鍵時,即是通知BASIC解釋程序檢查指令有無錯誤,如果沒有發(fā)現(xiàn)錯誤,就將指令編譯成機器語言并執(zhí)行。所有這些工作完成的速度極快!讓我們再多看幾個例子。
    通過在計算式中加逗號的方式,我們可以使BASIC在同一行里顯示兩個數(shù)值。
    PRINT 1,2,3,4,5
    12345
    PRINT I,2,3,4,5
    12345
    注意看發(fā)生了什么變化: BASIC將顯示行劃分成了打印區(qū)。 這些打印區(qū)各自空出的列數(shù)相同,即將80列的屏幕劃分成了5個打印區(qū)(具體數(shù)字取決于BASIC文本) 數(shù)值間的逗號使得BASIC在顯示每個數(shù)值時都要跳過一個打印區(qū)。通過使用逗號,我們可打印出整齊的各列來。在第二個例子中打印行各數(shù)值間的多余空格不會影響到最終結(jié)果之間的間隔。
    如果數(shù)字的值為負,則顯示時其前面有一負號:若數(shù)字的值為正,顯示時其前會有一空格。在大多數(shù)BASIC語句中,數(shù)值顯示時其后亦有一空格。
    如果你想使打印出的數(shù)值一個接一個地排列,可使用分號“;” ,它將抑制數(shù)值向下一個打印區(qū)的移動?,F(xiàn)舉一例如下:
    PRINT I;-2,3+3
    1-26
    使用分號后,打印出的結(jié)果除了其前面的符號和后而的空格外, 將一個緊接著一個顯示。
    逗號和分號可用作分隔數(shù)值的工具。因此,數(shù)值999中間就不應(yīng)該 有逗號I要打印12,345我們必須鍵入“PRITN12345”。如果編寫成“PRfNT12,345”BASIC將把它編譯 成兩個數(shù)值“12”和“345”。
    前述的討論主要是針對屏幕打印的;實際上,如果你的系統(tǒng)配置有一臺打印機的話,同樣的信息也 可以通過打印機打印出來〕在大多 數(shù)系統(tǒng)中,這可通過“LPRINT “語 句來完成。LPRINT與PRINT的語法 格式是一樣的。只不過,LPRINT指 示輸出到打印機上而不是屏幕上。 在有些系統(tǒng)中,同時按住!Ctrl]鍵私 [PrtSc]或[Ctrll鍵和IN鍵可使所有輸出既顯示在屏幕上,又被送往打c-. 機。這就象一個肘節(jié)開關(guān),(例丈 第一次按)Ctrl]鍵「」!Prtsc]鍵)將步I開計算機和打印機間的聯(lián)系;第二次 按I Ctril鍵和[PrtScj鍵將切斷聯(lián)系 由于各BASIC文本的差別很大,在這 里我們不打算詳細講述LPRINT.