Add User Input and Output
32
User-Input-and-Output.md
Normal file
32
User-Input-and-Output.md
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
In Ground, there are 3 commands that are used for I/O. These are `stdin`, `stdout`, and `stdlnout`.
|
||||||
|
|
||||||
|
## **Stdin**
|
||||||
|
The `stdin` command allows user input within the terminal. It allows the user to input a value, and it will store the input in a variable.
|
||||||
|
|
||||||
|
The syntax is: `stdin &variable`.
|
||||||
|
|
||||||
|
## **Stdout**
|
||||||
|
The `stdout` command allows the program to output text to the terminal.
|
||||||
|
|
||||||
|
The syntax is: `stdout $string`
|
||||||
|
|
||||||
|
## **Stdlnout**
|
||||||
|
The `stdlnout` command allows the program to output text to the terminal. Unlike `stdout`, `stdlnout` will automatically append a newline character to the end of any string.
|
||||||
|
Please note that this command is not yet functional in [GroundPY](url=https://git.maxwellj.xyz/ground/GroundPY) - a workaround is to simply append a newline character to the end of the string.
|
||||||
|
|
||||||
|
The syntax is: `stdout &variable`
|
||||||
|
|
||||||
|
## **Example Program**
|
||||||
|
This program asks the user "Do you like cheese?" until the user inputs "yes" (must be lowercase).
|
||||||
|
```
|
||||||
|
@begin
|
||||||
|
stdout "Do you like cheese? "
|
||||||
|
stdin &userin
|
||||||
|
equal $userin "yes" &condition
|
||||||
|
if $condition %end
|
||||||
|
stdlnout "That is sad"
|
||||||
|
jump %begin
|
||||||
|
@end
|
||||||
|
stdlnout "Awesome! I do too!"
|
||||||
|
```
|
||||||
|
The program outputs `"Do you like cheese? "`, and waits for a reply. If the reply is `"yes"`, it will jump to the end, outputting `"Awesome! I do too!"`. Otherwise, it outputs `"That is sad"`, and returns to the beginning.
|
||||||
Reference in New Issue
Block a user