Forgot to commit
[mono.git] / mcs / docs / ecma334 / 15.5.1.xml
1 <?xml version="1.0"?>
2 <clause number="15.5.1" title="Local variable declarations">
3   <paragraph>A <non_terminal where="15.5.1">local-variable-declaration</non_terminal> declares one or more local variables. <grammar_production><name><non_terminal where="15.5.1">local-variable-declaration</non_terminal></name> : <rhs><non_terminal where="11">type</non_terminal><non_terminal where="15.5.1">local-variable-declarators</non_terminal></rhs></grammar_production><grammar_production><name><non_terminal where="15.5.1">local-variable-declarator</non_terminal>s</name> : <rhs><non_terminal where="15.5.1">local-variable-declarator</non_terminal></rhs><rhs><non_terminal where="15.5.1">local-variable-declarators</non_terminal><terminal>,</terminal><non_terminal where="15.5.1">local-variable-declarator</non_terminal></rhs></grammar_production><grammar_production><name><non_terminal where="15.5.1">local-variable-declarator</non_terminal></name> : <rhs><non_terminal where="9.4.2">identifier</non_terminal></rhs><rhs><non_terminal where="9.4.2">identifier</non_terminal><terminal>=</terminal><non_terminal where="15.5.1">local-variable-initializer</non_terminal></rhs></grammar_production><grammar_production><name><non_terminal where="15.5.1">local-variable-initializer</non_terminal></name> : <rhs><non_terminal where="14.14">expression</non_terminal></rhs><rhs><non_terminal where="19.6">array-initializer</non_terminal></rhs></grammar_production></paragraph>
4   <paragraph>The type of a <non_terminal where="15.5.1">local-variable-declaration</non_terminal> specifies the type of the variables introduced by the declaration. </paragraph>
5   <paragraph>The type is followed by a list of <non_terminal where="15.5.1">local-variable-declarator</non_terminal>s, each of which introduces a new variable. A <non_terminal where="15.5.1">local-variable-declarator</non_terminal> consists of an identifier that names the variable, optionally followed by an &quot;=&quot; token and a <non_terminal where="15.5.1">local-variable-initializer</non_terminal> that gives the initial value of the variable. </paragraph>
6   <paragraph>The value of a local variable is obtained in an expression using a <non_terminal where="14.5.2">simple-name</non_terminal> (<hyperlink>14.5.2</hyperlink>), and the value of a local variable is modified using an assignment (<hyperlink>14.13</hyperlink>). A local variable must be definitely assigned (<hyperlink>12.3</hyperlink>) at each location where its value is obtained. </paragraph>
7   <paragraph>The scope of a local variable declared in a <non_terminal where="15.5.1">local-variable-declaration</non_terminal> is the block in which the declaration occurs. It is an error to refer to a local variable in a textual position that precedes the  <non_terminal where="15.5.1">local-variable-declarator</non_terminal> of the local variable. Within the scope of a local variable, it is a compile-time error to declare another local variable or constant with the same name. </paragraph>
8   <paragraph>A local variable declaration that declares multiple variables is equivalent to multiple declarations of single variables with the same type. Furthermore, a variable initializer in a local variable declaration corresponds exactly to an assignment statement that is inserted immediately after the declaration. </paragraph>
9   <paragraph>
10     <example>[Example: The example <code_example><![CDATA[
11 void F() {  
12    int x = 1, y, z = x * 2;  
13 }  
14 ]]></code_example>corresponds exactly to <code_example><![CDATA[
15 void F() {  
16    int x; x = 1;  
17    int y;  
18    int z; z = x * 2;  
19 }  
20 ]]></code_example>end example]</example>
21   </paragraph>
22 </clause>