input Statement
Syntax
- <VARIABLE> is the name of a String or Number variable to store the user's input.
Usage
The
input statement reads a line of text from the user's keyboard.
It waits for the user to type something and then press Enter.
Then it stores their entered value into the specified variable.
The example below uses the
print statement to prompt the user to enter their name.
After the user types a name and presses Enter, that name is stored in the
name variable.
Then,
print is used again to greet the user by name.
sub Main()
print "Name? ";
dim name as String
input name
print "Hi "; name; "!"
end sub
╔═ Console ═════════╗ ╔═ Console ═════════╗ ╔═ Console ═════════╗
║Name? █ ║ ║Name? Alice█ ║ ║Name? Alice ║
║ ║──►║ ║──►║Hi Alice! ║
║ ║ ║ ║ ║█ ║
╚═══════════════════╝ ╚═══════════════════╝ ╚═══════════════════╝
The computer displays The user types the The user hits Enter.
the prompt "Name?" name "Alice" The computer responds.