Vala Reference Manual


Selection statements

The if statement selects a statement for execution based on the value of a boolean expression.

if-statement: if ( boolean-expression ) embedded-statement if ( boolean-expression ) embedded-statement else embedded-statement

Iteration statements

The while statement conditionally executes an embedded statement zero or more times.

while-statement: while ( boolean-expression ) embedded-statement

The do statement conditionally executes an embedded statement one or more times.

do-statement: do embedded-statement while ( boolean-expression ) ;

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.

for-statement: for ( [for-initializer] ; [for-condition] ; [for-iterator] ) embedded-statement for-initializer: local-variable-declaration statement-expression-list for-condition: boolean-expression for-iterator: statement-expression-list statement-expression-list: statement-expression statement-expression-list , statement-expression

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).

The foreach statement enumerates the elements of a collection, executing an embedded statement for each element of the collection.

foreach-statement: foreach ( type identifier in expression ) embedded-statement

Jump statements

The break statement exits the nearest enclosing switch, while, do, for, or foreach statement.

break-statement: break ;

The continue statement starts a new iterataion of the nearest enclosing while, do, for, or foreach statement.

continue-statement: continue ;

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.

The return statement returns control to the caller of the function member in which the return statement appears.

return-statement: return [expression] ;

The throw statement throws an exception.

throw-statement: throw expression ;

Try statement

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.

try-statement: try block catch-clauses try block [catch-clauses] finally-clause catch-clauses: specific-catch-clause [specific-catch-clauses] general-catch-clause specific-catch-clause: specific-catch-clause specific-catch-clauses specific-catch-clause specific-catch-clause: catch ( error-type identifier ) block general-catch-clause: catch block finally-clause: finally block