Add Input Keyword
21
Input-Keyword.md
Normal file
21
Input-Keyword.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
Keyword: `input` (or `stdin`)
|
||||||
|
|
||||||
|
Syntax: `input &str`
|
||||||
|
|
||||||
|
Time Complexity:
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
The `input` keyword allows you to get user input via stdin. When this line is reached, the program will wait for the user to input text. After this, the argument variable is set to the inputted string.
|
||||||
|
|
||||||
|
## Example Usage
|
||||||
|
We can make a simple [truth machine](https://esolangs.org/wiki/Truth-machine) by checking if the input is 0 or other.
|
||||||
|
```grnd
|
||||||
|
input &str
|
||||||
|
equal $str "0" &cond # check if char is "0"
|
||||||
|
if $cond %outonce # if char is 0, jump to the bottom script
|
||||||
|
@loop # otherwise loop
|
||||||
|
println $char # append char to stdout
|
||||||
|
jump %loop # loop forever
|
||||||
|
@outonce
|
||||||
|
println "0" # append 0 to stdout
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user