OSDN Git Service

【更新内容】
[ring-lang-081/ring.git] / docs / en / source / getinput.txt
1 .. index:: 
2         single: Getting Input; Introduction
3
4 =============
5 Getting Input
6 =============
7
8 We can get input from the keyboard using 
9
10 * The Give Command
11 * The GetChar() Function
12 * The Input() Function
13
14 .. index:: 
15         pair: Getting Input; Give Command
16
17 Give Command
18 ============
19
20 Syntax:
21
22 .. code-block:: ring
23
24         Give VariableName
25
26 Example:
27
28 .. code-block:: ring
29
30         See "Enter the first number : " Give nNum1
31         See "Enter the second number : " Give nNum2
32         See "Sum : " + ( 0 + nNum1 + nNum2 )
33  
34 Output:
35
36 .. code-block:: ring
37
38         Enter the first number : 3
39         Enter the second number : 4
40         Sum : 7
41
42 .. index:: 
43         pair: Getting Input; GetChar()
44
45 GetChar() Function
46 ==================
47
48 We can get one character from the standard input using the GetChar() function
49
50 Syntax:
51
52 .. code-block:: ring
53
54         GetChar() ---> Character
55
56 Example:
57
58 .. code-block:: ring
59
60         While True
61                 See "
62                         Main Menu
63                         (1) Say Hello
64                         (2) Exit
65                     " 
66                 Option = GetChar()
67                 GetChar() GetChar()  # End of line
68
69                 # the previous two lines can be replaced with the next line
70                 # Give Option
71
72                 if Option = 1
73                         see "Enter your name : " give cName 
74                         see "Hello " + cName
75                 else
76                         bye
77                 ok
78         End
79
80 .. index:: 
81         pair: Getting Input; Input()
82
83 Input() Function
84 ================
85
86 We can get input from the keyboard using the Input() function
87
88 Syntax:
89
90 .. code-block:: ring
91
92         Input(nCount) ---> string
93
94 The function will wait until nCount characters (at least) are read
95
96 Example:
97
98 .. code-block:: ring
99
100         See "Enter message (30 characters) : " cMsg = input(30)
101         See "Message : " + cMsg