OSDN Git Service

【更新内容】
[ring-lang-081/ring.git] / docs / en / target / getting_started.txt
1 .. index:: 
2         single: Getting Started - First Style; Introduction
3
4 =============================
5 Getting Started - First Style
6 =============================
7
8 .. index:: 
9         pair: Getting Started - First Style; Hello World
10
11 Hello World
12 ===========
13
14 The next program prints the Hello World message on the screen (std-out).
15
16 .. code-block:: ring
17
18         see "Hello World"
19
20 .. index:: 
21         pair: Getting Started - First Style; Run the program
22
23 Run the program
24 ===============
25
26 to run the program, save the code in a file, for example : hello.ring
27 then from the command line or terminal, run it using Ring
28
29 .. code-block:: ring
30
31         ring hello.ring
32
33
34 .. index:: 
35         pair: Getting Started - First Style; Create Executable File
36
37 Create Executable File
38 ======================
39
40 Using Ring2EXE we can create executable file for our application
41
42 .. code-block:: ring
43
44         ring2exe hello.ring -static
45
46 .. index:: 
47         pair: Getting Started - First Style; Not Case-Sensitive
48
49 Not Case-Sensitive
50 ==================
51
52 Since the Ring language is not case-sensitive, the same program can
53 be written in different styles
54
55 .. tip:: It's better to select one style and use it in all of the program source code
56
57 .. code-block:: ring
58
59         SEE "Hello World"
60
61 .. code-block:: ring
62
63         See "Hello World"
64
65
66 .. index:: 
67         pair: Getting Started - First Style; Multi-Line literals
68
69 Multi-Line literals
70 ===================
71
72 Using Ring we can write multi-line literal, see the next example
73
74 .. code-block:: ring
75
76         See "
77                 Hello 
78                 Welcome to the Ring programming language
79                 How are you?
80
81             "
82
83 Also you can use the nl variable to insert new line
84 and you can use the + operator to concatenate strings
85
86 As we have NL for new lines, we have Tab and CR (Carriage return) too!
87
88 .. note:: nl value means a new line and the actual codes that
89          represent a newline is different between operating systems
90
91 .. code-block:: ring
92
93         See "Hello" + nl + "Welcome to the Ring programming language" + 
94             nl + "How are you?"
95
96 .. index:: 
97         pair: Getting Started - First Style; Getting Input
98
99 Getting Input
100 =============
101
102 You can get the input from the user using the give command
103
104 .. code-block:: ring
105
106         See "What is your name? "
107         Give cName
108         See "Hello " + cName
109
110 .. index:: 
111         pair: Getting Started - First Style; No Explicit End For Statements
112
113 No Explicit End For Statements
114 ==============================
115
116 You don't need to use ';' or press ENTER to separate statements.
117 The previous program can be written in one line.
118
119 .. code-block:: ring
120
121         See "What is your name? " give cName see "Hello " + cName
122
123 .. index:: 
124         pair: Getting Started - First Style; Using ? to print expression then new line
125
126 Using ? to print expression then new line
127 =========================================
128
129 It's common to print new line after printing an expression, We can use the ? operator to do that!
130
131 Example:
132
133 .. code-block:: ring
134
135         ? "Hello, World!"
136         for x = 1 to 10
137                 ? x
138         next
139
140 Output:
141
142 .. code-block:: none
143
144         Hello, World!
145         1
146         2
147         3
148         4
149         5
150         6
151         7
152         8
153         9
154         10
155
156 .. index:: 
157         pair: Getting Started - First Style; Writing Comments
158
159 Writing Comments
160 ================
161
162 We can write one line comments and multi-line comments
163
164 The comment starts with # or //
165
166 Multi-lines comments are written between /* and */
167
168 .. code-block:: ring
169
170
171         /* 
172                 Program Name : My first program using Ring
173                 Date         : 2016.09.09
174                 Author       : Mahmoud Fayed
175         */
176
177         See "What is your name? "       # print message on screen
178         give cName                      # get input from the user
179         see "Hello " + cName            # say hello!
180
181         // See "Bye!"
182
183 .. note:: Using // to comment a lines of code is just a code style.
184
185
186