跳轉到內容

環/教程/獲取輸入

來自華夏公益教科書,開放的書籍,開放的世界
<

獲取輸入

[編輯 | 編輯原始碼]

我們可以使用以下方法從鍵盤獲取輸入

  • 給出命令
  • GetChar() 函式
  • Input() 函式

給出命令

[編輯 | 編輯原始碼]

語法

	Give VariableName

示例

	See "Enter the first number : " Give nNum1
	See "Enter the second number : " Give nNum2
	See "Sum : " + ( 0 + nNum1 + nNum2 )

輸出

	Enter the first number : 3
	Enter the second number : 4
	Sum : 7

GetChar() 函式

[編輯 | 編輯原始碼]

我們可以使用 GetChar() 函式從標準輸入獲取一個字元

語法

	GetChar() ---> Character

示例

	While True
		See "
			Main Menu
			(1) Say Hello
			(2) Exit
		    " 
		Option = GetChar()
		GetChar() GetChar()  # End of line

		# the previous two lines can be replaced with the next line
		# Give Option

		if Option = 1
			see "Enter your name : " give cName 
			see "Hello " + cName
		else
			bye
		ok
	End

Input() 函式

[編輯 | 編輯原始碼]

我們可以使用 Input() 函式從鍵盤獲取輸入

語法

	Input(nCount) ---> string

該函式將等待直到讀取到至少 nCount 個字元

示例

	See "Enter message (30 characters) : " cMsg = input(30)
	See "Message : " + cMsg


華夏公益教科書