Ring/Lessons/HelloWorld
外觀
< Ring
下一個程式將 Hello World 訊息列印到螢幕(標準輸出)。
see "Hello World"
要執行程式,請將程式碼儲存到一個檔案,例如:hello.ring,然後從命令列或終端使用 ring 直譯器執行它。
ring hello.ring
由於 Ring 語言不區分大小寫,因此同一個程式可以用不同的風格編寫。
.. tip:: 最好選擇一種風格,並在所有程式原始碼中使用它。
SEE "Hello World" See "Hello World"
使用 Ring,我們可以編寫多行文字,請看下一個例子。
See "
Hello
Welcome to the Ring programming language
How are you?
"您也可以使用 nl 常量插入新行,並可以使用 + 運算子連線字串。
.. note:: nl 值表示一個新行,而表示新行的實際程式碼在不同的作業系統之間是不同的。
See "Hello" + nl + "Welcome to the Ring programming language" +
nl + "How are you?"
您可以使用 give 命令從使用者獲取輸入。
See "What is your name? "
Give cName
See "Hello " + cName
您不需要使用 ';' 或按 ENTER 來分隔語句。前面的程式可以寫在一行中。
See "What is your name? " give cName see "Hello " + cName
我們可以編寫單行註釋和多行註釋。
註釋以 # 或 // 開頭。
多行註釋寫在 /* 和 */ 之間。
/*
Program Name : My first program using Ring
Date : 2015.05.08
Author : Mahmoud Fayed
*/
See "What is your name? " # print message on screen
give cName # get input from the user
see "Hello " + cName # say hello!
// See "Bye!"
.. note:: 使用 // 註釋程式碼行只是一種程式碼風格。