libgda-4.0, gedit-2.20: Fix gedit typo and GdaXaTransactionId.data
[vala-lang.git] / doc / vala / statements.xml
blob121b27a211555f2b9fbb0c40dc2625fc85441d0d
1 <?xml version="1.0"?>
2 <section id="statements">
3         <h>Statements</h>
4         <section id="selection">
5                 <h>Selection statements</h>
6                 <p>The if statement selects a statement for execution based on the value of a boolean expression.</p>
7                 <blockquote>
8 if-statement:
9         <l>if (</l> boolean-expression <l>)</l> embedded-statement
10         <l>if (</l> boolean-expression <l>)</l> embedded-statement <l>else</l> embedded-statement
11                 </blockquote>
12         </section>
13         <section id="iteration">
14                 <h>Iteration statements</h>
15                 <p>The while statement conditionally executes an embedded statement zero or more times.</p>
16                 <blockquote>
17 while-statement:
18         <l>while (</l> boolean-expression <l>)</l> embedded-statement
19                 </blockquote>
20                 <p>The do statement conditionally executes an embedded statement one or more times.</p>
21                 <blockquote>
22 do-statement:
23         <l>do</l> embedded-statement <l>while (</l> boolean-expression <l>) ;</l>
24                 </blockquote>
25                 <p>The for statement evaluates a sequence of initialization expressions and then, while a condition is true, repeatedly executes an embedded statement and evaluates a sequence of iteration expressions.</p>
26                 <blockquote>
27 for-statement:
28         <l>for (</l> [for-initializer] <l>;</l> [for-condition] <l>;</l> [for-iterator] <l>)</l> embedded-statement
30 for-initializer:
31         local-variable-declaration
32         statement-expression-list
34 for-condition:
35         boolean-expression
37 for-iterator:
38         statement-expression-list
40 statement-expression-list:
41         statement-expression
42         statement-expression-list <l>,</l> statement-expression
43                 </blockquote>
44                 <p>Within the embedded statement of a for statement, a break statement can be used to transfer control to the end point of the for statement (thus ending iteration of the embedded statement), and a continue statement can be used to transfer control to the end point of the embedded statement (thus executing another iteration of the for statement).</p>
45                 <p>The foreach statement enumerates the elements of a collection, executing an embedded statement for each element of the collection.</p>
46                 <blockquote>
47 foreach-statement:
48         <l>foreach (</l> type identifier <l>in</l> expression <l>)</l> embedded-statement
49                 </blockquote>
50         </section>
51         <section id="jump">
52                 <h>Jump statements</h>
53                 <p>The break statement exits the nearest enclosing switch, while, do, for, or foreach statement.</p>
54                 <blockquote>
55 break-statement:
56         <l>break ;</l>
57                 </blockquote>
58                 <p>The continue statement starts a new iterataion of the nearest enclosing while, do, for, or foreach statement.</p>
59                 <blockquote>
60 continue-statement:
61         <l>continue ;</l>
62                 </blockquote>
63                 <p>When multiple while, do, for, or foreach statements are nested within each other, a continue statement applies only to the innermost statement. If a continue statement is not eclosed by a while, do, for, or foreach statement, a compile-time error occurs.</p>
64                 <p>The return statement returns control to the caller of the function member in which the return statement appears.</p>
65                 <blockquote>
66 return-statement:
67         <l>return</l> [expression] <l>;</l>
68                 </blockquote>
69                 <p>The throw statement throws an exception.</p>
70                 <blockquote>
71 throw-statement:
72         <l>throw</l> expression <l>;</l>
73                 </blockquote>
74         </section>
75         <section id="try">
76                 <h>Try statement</h>
77                 <p>The try statement provides a mechanism for catching exceptions that occur during execution of a block. Furthermore, the try statement provides the ability to specify a block of code that is always executed when control leaves the try statement.</p>
78                 <blockquote>
79 try-statement:
80         <l>try</l> block catch-clauses
81         <l>try</l> block [catch-clauses] finally-clause
83 catch-clauses:
84         specific-catch-clause
85         [specific-catch-clauses] general-catch-clause
87 specific-catch-clause:
88         specific-catch-clause
89         specific-catch-clauses specific-catch-clause
91 specific-catch-clause:
92         <l>catch (</l> error-type identifier <l>)</l> block
94 general-catch-clause:
95         <l>catch</l> block
97 finally-clause:
98         <l>finally</l> block
99                 </blockquote>
100         </section>
101 </section>