Non-\/block statements in Qore are always terminated by a semi-\/colon {\ttfamily \char`\"{};\char`\"{}} as in Perl, C, C++, or Java. Statements can be grouped into blocks, which are delimited by curly brackets {\ttfamily \char`\"{}\{\char`\"{}} and {\ttfamily \char`\"{}\}\char`\"{}} containing zero or more semi-\/colon delimited statements, as in C or Java. Like C, C++, and Java, but unlike perl, any Qore statement taking a statement modifier will accept a single statement or a statement block.

A statement can be any of the following (note that statements are also recursively defined, and note furthermore that all examples are given in \mbox{\hyperlink{parse_directives_new-style}{\%new-\/style}})\+:

{\bfseries Qore Statements}  \tabulinesep=1mm
\begin{longtabu} spread 0pt [c]{*{3}{|X[-1]}|}
\hline
{\bfseries Type} &{\bfseries Examples} &{\bfseries Reference}  \\\cline{1-3}
An expression that changes an lvalue &
\begin{DoxyCode}
var = 1;
\end{DoxyCode}

\begin{DoxyCode}
var += 5;
\end{DoxyCode}

\begin{DoxyCode}
var[1].count++;
\end{DoxyCode}

\begin{DoxyCode}
shift var.key[i];
\end{DoxyCode}
 &\mbox{\hyperlink{expressions}{Expressions}}  \\\cline{1-3}
An expression with the \mbox{\hyperlink{operators_new}{new operator}} &
\begin{DoxyCode}
new ObjectClass(1, 2, 3);
\end{DoxyCode}
 &\mbox{\hyperlink{operators_new}{New Value Operator (new)}}  \\\cline{1-3}
An expression with the \mbox{\hyperlink{operators_background}{background operator}} &
\begin{DoxyCode}
background function();
\end{DoxyCode}
 &\mbox{\hyperlink{operators_background}{Background Operator (background)}}  \\\cline{1-3}
An \mbox{\hyperlink{statements_if}{if statement}} &
\begin{DoxyCode}
\textcolor{keywordflow}{if} (var == 3) \{\}
\end{DoxyCode}
 &\mbox{\hyperlink{statements_if}{if and else Statements}}  \\\cline{1-3}
An \mbox{\hyperlink{statements_if}{if ... else}} statement &
\begin{DoxyCode}
\textcolor{keywordflow}{if} (var == 3) \{\} \textcolor{keywordflow}{else} \{\}
\end{DoxyCode}
 &\mbox{\hyperlink{statements_if}{if and else Statements}}  \\\cline{1-3}
A \mbox{\hyperlink{statements_while}{while statement}} &
\begin{DoxyCode}
\textcolor{keywordflow}{while} (var < 10) \{\}
\end{DoxyCode}
 &\mbox{\hyperlink{statements_while}{while Statements}}  \\\cline{1-3}
A \mbox{\hyperlink{statements_do}{do while statement}} &
\begin{DoxyCode}
do \{\} \textcolor{keywordflow}{while} (\textcolor{keyword}{True});
\end{DoxyCode}
 &\mbox{\hyperlink{statements_do}{do while Statements}}  \\\cline{1-3}
A \mbox{\hyperlink{statements_for}{for statement}} &
\begin{DoxyCode}
\textcolor{keywordflow}{for} (int i = 0; i < 10; ++ i) \{\}
\end{DoxyCode}
 &\mbox{\hyperlink{statements_for}{for Statements}}  \\\cline{1-3}
A \mbox{\hyperlink{statements_foreach}{foreach statement}} &
\begin{DoxyCode}
foreach softint i \textcolor{keywordflow}{in} (list) \{\}
\end{DoxyCode}
 &\mbox{\hyperlink{statements_foreach}{foreach Statements}}  \\\cline{1-3}
A \mbox{\hyperlink{statements_switch}{switch statement}} &
\begin{DoxyCode}
switch (var) \{ case =~ /error/: throw \textcolor{stringliteral}{"ERROR"}, var; default: \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"%s\(\backslash\)n"}, var); \}
\end{DoxyCode}
 &\mbox{\hyperlink{statements_switch}{switch Statements}}  \\\cline{1-3}
A \mbox{\hyperlink{statements_return}{return statement}} &
\begin{DoxyCode}
\textcolor{keywordflow}{return} val;
\end{DoxyCode}
 &\mbox{\hyperlink{statements_return}{return Statements}}  \\\cline{1-3}
A \mbox{\hyperlink{variables_variable_declarations}{local variable declaration}} &
\begin{DoxyCode}
string var;
\end{DoxyCode}

\begin{DoxyCode}
my (int a, string b, bool c);
\end{DoxyCode}
 &\mbox{\hyperlink{variables}{Variables}}, \mbox{\hyperlink{variables_variable_declarations}{Variable Declarations and Lexical Scope}}  \\\cline{1-3}
A \mbox{\hyperlink{variables_variable_declarations}{global variable declaration}} &
\begin{DoxyCode}
our int var;
\end{DoxyCode}

\begin{DoxyCode}
our (float a, int b, hash c);
\end{DoxyCode}
 &\mbox{\hyperlink{variables}{Variables}}, \mbox{\hyperlink{variables_variable_declarations}{Variable Declarations and Lexical Scope}}  \\\cline{1-3}
A \mbox{\hyperlink{qore_functions}{function call}} &
\begin{DoxyCode}
calculate(this, that, the\_other);
\end{DoxyCode}
 &\mbox{\hyperlink{qore_functions}{Functions}}, \mbox{\hyperlink{qore_classes_object_method_calls}{Object Method Calls}}, \mbox{\hyperlink{expressions_static_method_calls}{Static Method Calls}}, \mbox{\hyperlink{expressions_closure}{Closures}}, \mbox{\hyperlink{expressions_call_reference}{Call References}}  \\\cline{1-3}
A \mbox{\hyperlink{statements_continue}{continue statement}} &
\begin{DoxyCode}
\textcolor{keywordflow}{continue};
\end{DoxyCode}
 &\mbox{\hyperlink{statements_continue}{continue Statements}}  \\\cline{1-3}
A \mbox{\hyperlink{statements_break}{break statement}} &
\begin{DoxyCode}
\textcolor{keywordflow}{break};
\end{DoxyCode}
 &\mbox{\hyperlink{statements_break}{break Statements}}  \\\cline{1-3}
A statement block &
\begin{DoxyCode}
\{\}
\end{DoxyCode}
 &zero or more statements enclosed in curly brackets  \\\cline{1-3}
A \mbox{\hyperlink{statements_throw}{throw statement}} &
\begin{DoxyCode}
throw \textcolor{stringliteral}{"ERROR"}, description;
\end{DoxyCode}
 &\mbox{\hyperlink{statements_throw}{throw Statements}}  \\\cline{1-3}
A \mbox{\hyperlink{statements_try}{try and catch statement}} &
\begin{DoxyCode}
\textcolor{keywordflow}{try} \{ func(); \} catch (hash ex) \{ \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"%s:%d: %s: %s\(\backslash\)n"}, ex.file, ex.line, ex.err, ex.desc); \}
\end{DoxyCode}
 &\mbox{\hyperlink{statements_try}{try and catch Statements}}  \\\cline{1-3}
A \mbox{\hyperlink{statements_rethrow}{rethrow statement}} &
\begin{DoxyCode}
rethrow;
\end{DoxyCode}
 &\mbox{\hyperlink{statements_rethrow}{rethrow Statements}}  \\\cline{1-3}
A \mbox{\hyperlink{statements_thread_exit}{thread\+\_\+exit statement}} &
\begin{DoxyCode}
thread\_exit;
\end{DoxyCode}
 &\mbox{\hyperlink{statements_thread_exit}{thread\+\_\+exit Statements}}  \\\cline{1-3}
A \mbox{\hyperlink{statements_context}{context statement}} &
\begin{DoxyCode}
context top (q) \{\}
\end{DoxyCode}
 &\mbox{\hyperlink{statements_context}{context Statements}}  \\\cline{1-3}
A \mbox{\hyperlink{statements_summarize}{summarize statement}} &
\begin{DoxyCode}
summarize (q) by (%date) where (%id != NULL) \{\}
\end{DoxyCode}
 &\mbox{\hyperlink{statements_summarize}{summarize Statements}}  \\\cline{1-3}
A \mbox{\hyperlink{statements_subcontext}{subcontext statement}} &
\begin{DoxyCode}
subcontext where (%type == \textcolor{stringliteral}{"INBOUND"} ) \{\}
\end{DoxyCode}
 &\mbox{\hyperlink{statements_subcontext}{subcontext Statements}}  \\\cline{1-3}
An \mbox{\hyperlink{statements_on_exit}{on\+\_\+exit statement}} &
\begin{DoxyCode}
on\_exit l.unlock();
\end{DoxyCode}
 &\mbox{\hyperlink{statements_on_exit}{on\+\_\+exit Statements}}  \\\cline{1-3}
An \mbox{\hyperlink{statements_on_success}{on\+\_\+success statement}} &
\begin{DoxyCode}
on\_success ds.commit();
\end{DoxyCode}
 &\mbox{\hyperlink{statements_on_success}{on\+\_\+success Statements}}  \\\cline{1-3}
An \mbox{\hyperlink{statements_on_error}{on\+\_\+error statement}} &
\begin{DoxyCode}
on\_error ds.rollback();
\end{DoxyCode}
 &\mbox{\hyperlink{statements_on_error}{on\+\_\+error Statements}}  \\\cline{1-3}
\end{longtabu}




 \hypertarget{statements_if}{}\section{if and else Statements}\label{statements_if}
\begin{DoxyParagraph}{Synopsis}
The {\ttfamily {\bfseries if}} statement allows for conditional logic in a Qore program\textquotesingle{}s flow; the syntax is similar to that of C, C++, or Java.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily {\bfseries if}} {\ttfamily (}{\itshape \mbox{\hyperlink{expressions}{expression}}}{\ttfamily )}~\newline
 ~~~~{\itshape \mbox{\hyperlink{statements}{statement}}}~\newline
 {\ttfamily \mbox{[}{\bfseries else}} ~\newline
 ~~~~{\itshape \mbox{\hyperlink{statements}{statement}}}{\ttfamily \mbox{]}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
Qore if statements work like if statements in C or Java. If the result of evaluating the expression converted to a \mbox{\hyperlink{basic_data_types_boolean}{Boolean}} value is \mbox{\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True}}, then the first statement (which can also be a block) is executed. If the result is \mbox{\hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False}}, and there is an {\ttfamily {\bfseries else}} keyword after the first statement, the following statement is executed.
\end{DoxyParagraph}
\begin{DoxyNote}{Note}
Any expression that evaluates to a non-\/zero integer value will be converted to a \mbox{\hyperlink{basic_data_types_boolean}{Boolean}} \mbox{\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True}}. Any expression that evaluates to zero value is interpreted as \mbox{\hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False}}. This is more like C and Java\textquotesingle{}s behavior and not like Perl\textquotesingle{}s (where any non-\/null string except \char`\"{}0\char`\"{} is \mbox{\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True}}). To simulate Perl\textquotesingle{}s boolean evaluation, use \mbox{\hyperlink{class_qore_1_1zzz8valuezzz9_a3a66486cee14aa073cf90fbed5a23edd}{Qore\+::zzz8valuezzz9\+::val()}}.
\end{DoxyNote}


 \hypertarget{statements_for}{}\section{for Statements}\label{statements_for}
\begin{DoxyParagraph}{Synopsis}
The Qore {\ttfamily {\bfseries for}} statement is most similar to the for statement in C and Java, or the non array iterator for statement in Perl. This statement is ideal for loops that should execute a given number of times, then complete. Each of the three expressions in the for statement is optional and may be omitted. To iterate through a list without directly referencing list index values, see the \mbox{\hyperlink{statements_foreach}{foreach statement}}.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily {\bfseries for}} {\ttfamily (} {\itshape \mbox{\hyperlink{expressions}{\mbox{[}initial\+\_\+expression\mbox{]}}}}{\ttfamily ;} {\itshape \mbox{\hyperlink{expressions}{\mbox{[}test\+\_\+expression\mbox{]}}}}{\ttfamily ;} {\itshape \mbox{\hyperlink{expressions}{\mbox{[}iterator\+\_\+expression\mbox{]}}}})~\newline
 ~~~~{\itshape \mbox{\hyperlink{statements}{statement}}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
{\itshape \mbox{\hyperlink{expressions}{\mbox{[}initial\+\_\+expression\mbox{]}}}}~\newline
 The {\itshape initial\+\_\+expression} is executed only once at the start of each for loop. It is typically used to initialize a loop variable.~\newline
~\newline
 {\itshape \mbox{\hyperlink{expressions}{\mbox{[}test\+\_\+expression\mbox{]}}}}~\newline
 The {\itshape test\+\_\+expression} is executed at the start of each for loop iteration. If this expression evaluates to \mbox{\hyperlink{basic_data_types_boolean}{Boolean}} \mbox{\hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False}}, the loop will terminate.~\newline
~\newline
 {\itshape \mbox{\hyperlink{expressions}{\mbox{[}iterator\+\_\+expression\mbox{]}}}}~\newline
 The {\itshape iterator\+\_\+expression} is executed at the end of each for loop iteration. It is typically used to increment or decrement a loop variable that will be used in the test\+\_\+expression.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}
Here is an example of a for loop using a local variable\+:~\newline

\begin{DoxyCode}
\textcolor{keywordflow}{for} (int i = 0; i < 10; i++)
    \mbox{\hyperlink{group__string__functions_ga996c5d1686fbc245f0bc7a02012e6a33}{print}}(\textcolor{stringliteral}{"%d\(\backslash\)n"}, i);
\end{DoxyCode}

\end{DoxyParagraph}


 \hypertarget{statements_foreach}{}\section{foreach Statements}\label{statements_foreach}
\begin{DoxyParagraph}{Synopsis}
The Qore {\ttfamily {\bfseries foreach}} statement is most similar to the {\ttfamily {\bfseries for}} or {\ttfamily {\bfseries foreach}} array iterator statement in Perl. To iterate an action until a condition is \mbox{\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True}}, use the \mbox{\hyperlink{statements_for}{for statement}} instead.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily {\bfseries foreach}} {\ttfamily \mbox{[}{\bfseries my$\vert${\bfseries our}\mbox{]}} \mbox{[}}{\itshape \mbox{\hyperlink{data_type_declarations}{type}}}{\ttfamily \mbox{]}} variable {\ttfamily {\bfseries in}} {\ttfamily (}{\itshape \mbox{\hyperlink{expressions}{expression}}}{\ttfamily )}~\newline
 ~~~~{\itshape \mbox{\hyperlink{statements}{statement}}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
If {\itshape expression} does not evaluate to a list, then the variable will be assigned the value of the expression evaluation and the statement will only execute one time. Otherwise the variable will be assigned to each value of the list and the statement will be called once for each value.~\newline
~\newline
 If {\itshape expression} evaluates to an object inheriting the \mbox{\hyperlink{class_qore_1_1_abstract_iterator}{Abstract\+Iterator}} class, the {\bfseries {\ttfamily foreach}} operator iterates the object by calling \mbox{\hyperlink{class_qore_1_1_abstract_iterator_ab10d5694cc2fcd3b6689ea7494da79de}{Abstract\+Iterator\+:\+:next()}}, and the values assigned to the iterator variable on each iteration are the container values returned by \mbox{\hyperlink{class_qore_1_1_abstract_iterator_a1f7b94aa7237f59c4f959f4d33333d9a}{Abstract\+Iterator\+:\+:get\+Value()}}.~\newline
~\newline
 If possible, {\itshape expression} is evaluated using \mbox{\hyperlink{operators_op_functional}{lazy functional evaluation}}.~\newline
~\newline
 If {\itshape expression} evaluates to \mbox{\hyperlink{basic_data_types_nothing}{N\+O\+T\+H\+I\+NG}} (no value); then the loop is not executed at all.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}
Here is an example of a foreach loop using a local variable\+:~\newline

\begin{DoxyCode}
\textcolor{comment}{# if str\_list is a list of strings, this will remove all whitespace from the}
\textcolor{comment}{# strings; the reference in the list expression ensures that changes}
\textcolor{comment}{# to the iterator variable are written back to the list}
foreach string str \textcolor{keywordflow}{in} (\(\backslash\)str\_list)
    trim str;
\end{DoxyCode}
 Here is an example of a foreach loop using an object derived from \mbox{\hyperlink{class_qore_1_1_abstract_iterator}{Abstract\+Iterator}}\+:~\newline

\begin{DoxyCode}
hash h = (\textcolor{stringliteral}{"a"}: 1, \textcolor{stringliteral}{"b"}: 2);
foreach hash ih \textcolor{keywordflow}{in} (h.pairIterator())
    \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"%s = %y\(\backslash\)n"}, ih.key, ih.value);
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxyNote}{Note}

\begin{DoxyItemize}
\item If a reference ({\ttfamily \textbackslash{}lvalue\+\_\+expression}) is used as the list expression, any changes made to the {\ttfamily {\bfseries foreach}} iterator variable will be written back to the list (in which case any \mbox{\hyperlink{class_qore_1_1_abstract_iterator}{Abstract\+Iterator}} object is not iterated; references cannot be used with \mbox{\hyperlink{class_qore_1_1_abstract_iterator}{Abstract\+Iterator}} objects as such objects provide read-\/only iteration).
\item When used with \mbox{\hyperlink{parse_directives_new-style}{\%new-\/style}} (which is a recommended parse option) or \mbox{\hyperlink{parse_directives_allow-bare-refs}{\%allow-\/bare-\/refs}}, the {\ttfamily {\bfseries my} or} {\ttfamily {\bfseries our} keywords} are required with new variables or their type has to be declared, otherwise a parse exception will be raised
\end{DoxyItemize}
\end{DoxyNote}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{operators_map}{Map Operator (map)}} for a flexible way to iterate a list or \mbox{\hyperlink{class_qore_1_1_abstract_iterator}{Abstract\+Iterator}} object in a single expression
\end{DoxySeeAlso}


 \hypertarget{statements_switch}{}\section{switch Statements}\label{statements_switch}
\begin{DoxyParagraph}{Synopsis}
The Qore switch statement is similar to the switch statement in C and C++, except that the case values can be any expression that does not need run-\/time evaluation and can also be expressions with simple relational operators or regular expressions using the switch value as an implied operand.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily {\bfseries switch}} {\ttfamily (}{\itshape \mbox{\hyperlink{expressions}{expression}}}{\ttfamily ) \{}~\newline
 ~~{\ttfamily {\bfseries case}} {\itshape case\+\_\+expression}{\ttfamily \+:}~\newline
 ~~~~{\itshape \mbox{\hyperlink{statements}{\mbox{[}statement(s)...\mbox{]}}}}~\newline
 ~~{\ttfamily \mbox{[}{\bfseries default\+:}} ~\newline
 ~~~~{\itshape \mbox{\hyperlink{statements}{\mbox{[}statement(s)...\mbox{]}}}}{\ttfamily \mbox{]}}~\newline
 {\ttfamily \}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
switch (val) \{
    case < -1:
        \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"less than -1\(\backslash\)n"});
        \textcolor{keywordflow}{break};
    case \textcolor{stringliteral}{"string"}:
        \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"string\(\backslash\)n"});
        \textcolor{keywordflow}{break};
    case > 2007-01-22T15:00:00:
        \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"greater than 2007-01-22 15:00:00\(\backslash\)n"});
        \textcolor{keywordflow}{break};
    case /abc/:
        \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"string with 'abc' somewhere inside\(\backslash\)n"});
        \textcolor{keywordflow}{break};
    default:
        \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"default\(\backslash\)n"});
        \textcolor{keywordflow}{break};
\}
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
The first {\itshape expression} is evaluated and then compared to the value of each {\itshape case\+\_\+expression} in declaration order until one of the {\itshape case\+\_\+expressions} matches or is evaluated to \mbox{\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True}}. In this case all code up to a \mbox{\hyperlink{statements_break}{break statement}} is executed, at which time execution flow exits the {\ttfamily {\bfseries switch}} statement.~\newline
~\newline
 Unless relational operators are used, the comparisons are \char`\"{}hard\char`\"{} comparisons; no type conversions are done, so in order for a match to be made, both the value and types of the expressions must match exactly. When relational operators are used, the operators are executed exactly as they are in the rest of Qore, so type conversions may be performed if nesessary. The only exception to this is when both arguments are strings then a soft comparison is made in order to avoid the case that strings fail to match only because their encodings are different.~\newline
~\newline
 To use soft comparisons, you must explicitly specify the soft equals operator as follows\+:~\newline

\begin{DoxyCode}
switch (1) \{
    case == \textcolor{stringliteral}{"1"}: \mbox{\hyperlink{group__string__functions_ga996c5d1686fbc245f0bc7a02012e6a33}{print}}(\textcolor{stringliteral}{"true\(\backslash\)n"}); \textcolor{keywordflow}{break};
\}
\end{DoxyCode}
 ~\newline
 If no match is found and a default label has been given, then any statements after the default label will be executed. If a match is made, then the statements following that case label are executed.~\newline
~\newline
 To break out of the switch statement, use the \mbox{\hyperlink{statements_break}{break statement}}.~\newline
~\newline
 As with C and C++, if no \mbox{\hyperlink{statements_break}{break}} or \mbox{\hyperlink{statements_return}{return}} statement is encountered, program control will continue to execute through other {\ttfamily {\bfseries case}} blocks until on of the previous statements is encountered or until the end of the {\ttfamily {\bfseries switch}} statement.
\end{DoxyParagraph}
\label{statements_case_expressions}%
\Hypertarget{statements_case_expressions}%
 {\bfseries Valid Case Expression Operators}  \tabulinesep=1mm
\begin{longtabu} spread 0pt [c]{*{2}{|X[-1]}|}
\hline
{\bfseries Operator} &{\bfseries Description}  \\\cline{1-2}
{\ttfamily $>$} &\mbox{\hyperlink{operators_logical_greater_than_operator}{Greater Than Operator ($>$)}}  \\\cline{1-2}
{\ttfamily $>$=} &\mbox{\hyperlink{operators_logical_greater_than_or_equals_operator}{Greater Than Or Equals Operator ($>$=)}}  \\\cline{1-2}
{\ttfamily $<$} &\mbox{\hyperlink{operators_logical_less_than_operator}{Less Than Operator ($<$)}}  \\\cline{1-2}
{\ttfamily $<$=} &\mbox{\hyperlink{operators_logical_less_than_or_equals_operator}{Less Than Or Equals Operator ($<$=)}}  \\\cline{1-2}
{\ttfamily ==} &\mbox{\hyperlink{operators_logical_equality_operator}{Equals Operator (==)}} (with type conversions)  \\\cline{1-2}
{\ttfamily =$\sim$} &\mbox{\hyperlink{operators_regex_match_operator}{Regular Expression Match Operator (=$\sim$)}} (in this case the regular expression may be optionally given without the operator)  \\\cline{1-2}
{\ttfamily !$\sim$} &\mbox{\hyperlink{operators_regex_no_match_operator}{Regular Expression No Match Operator (!$\sim$)}}  \\\cline{1-2}
\end{longtabu}




 \hypertarget{statements_while}{}\section{while Statements}\label{statements_while}
\begin{DoxyParagraph}{Synopsis}
{\ttfamily {\bfseries while}} statements in Qore are similar to while statements in Perl, C and Java. They are used to loop while a given condition is \mbox{\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True}}.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily {\bfseries while}} {\ttfamily (}{\itshape \mbox{\hyperlink{expressions}{expression}}}{\ttfamily )}~\newline
 ~~~~{\itshape \mbox{\hyperlink{statements}{statement}}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
First the expression will be evaluated; if it evaluates to \mbox{\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True}}, then statement will be executed. If it evaluates to \mbox{\hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False}}, the loop terminates.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
int a = 1;
\textcolor{keywordflow}{while} (a < 10)
    a++;
\end{DoxyCode}

\end{DoxyParagraph}


 \hypertarget{statements_do}{}\section{do while Statements}\label{statements_do}
\begin{DoxyParagraph}{Synopsis}
{\ttfamily {\bfseries do}} {\ttfamily {\bfseries while}} statements in Qore are similar to do while statements in C. They are used to guarantee at least one iteration and loop until a given expression evaluates to \mbox{\hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False}}.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\bfseries {\ttfamily do}}~\newline
 ~~~~{\itshape \mbox{\hyperlink{statements}{statement}}} ~\newline
 {\ttfamily {\bfseries while}} {\ttfamily (}{\itshape \mbox{\hyperlink{expressions}{expression}}}{\ttfamily );}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
First, the {\itshape statement} will be executed, then the {\itshape expression} will be evaluated; if it evaluates to \mbox{\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True}}, then the loop iterates again. If it evaluates to \mbox{\hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False}}, the loop terminates.~\newline
~\newline
 The difference between {\ttfamily {\bfseries do}} {\ttfamily {\bfseries while}} statements and \mbox{\hyperlink{statements_while}{while statements}} is that the {\ttfamily {\bfseries do}} {\ttfamily {\bfseries while}} statement evaluates its loop expression at the end of the loop, and therefore guarantees at least one iteration of the loop.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
a = 1;
do
    a++;
\textcolor{keywordflow}{while} (a < 10);
\end{DoxyCode}

\end{DoxyParagraph}


 \hypertarget{statements_continue}{}\section{continue Statements}\label{statements_continue}
\begin{DoxyParagraph}{Synopsis}
Skips the rest of a loop and jumps right to the evaluation of the iteration expression.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\bfseries {\ttfamily continue};} 
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
The {\ttfamily {\bfseries continue}} statement affects loop processing; that is; it has an affect on \mbox{\hyperlink{statements_for}{for}}, \mbox{\hyperlink{statements_foreach}{foreach}}, \mbox{\hyperlink{statements_while}{while}}, \mbox{\hyperlink{statements_do}{do while}}, \mbox{\hyperlink{statements_context}{context}}, \mbox{\hyperlink{statements_summarize}{summarize}}, and \mbox{\hyperlink{statements_subcontext}{subcontext}} loop processing.~\newline
~\newline
 When this statement is encountered while executing a loop, execution control jumps immediately to the evaluation of the iteration expression, skipping any other statements that might otherwise be executed.
\end{DoxyParagraph}


 \hypertarget{statements_break}{}\section{break Statements}\label{statements_break}
\begin{DoxyParagraph}{Synopsis}
Exits immediately from a loop statement or \mbox{\hyperlink{statements_switch}{switch}} block.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\bfseries {\ttfamily break};} 
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
The {\ttfamily {\bfseries break}} statement affects loop processing; that is; it has an affect on \mbox{\hyperlink{statements_for}{for}}, \mbox{\hyperlink{statements_foreach}{foreach}}, \mbox{\hyperlink{statements_while}{while}}, \mbox{\hyperlink{statements_do}{do while}}, \mbox{\hyperlink{statements_context}{context}}, \mbox{\hyperlink{statements_summarize}{summarize}}, and \mbox{\hyperlink{statements_subcontext}{subcontext}} loop processing as well as on \mbox{\hyperlink{statements_switch}{switch}} block processing.~\newline
~\newline
 When this statement is encountered while executing a loop, the loop is immediately exited, and execution control passes to the next statement outside the loop.
\end{DoxyParagraph}


 \hypertarget{statements_throw}{}\section{throw Statements}\label{statements_throw}
\begin{DoxyParagraph}{Synopsis}
In order to throw an exception explicitly, the {\ttfamily {\bfseries throw}} statement must be used.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily {\bfseries throw}} expression;
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
The expression will be passed to the {\ttfamily {\bfseries catch}} block of a \mbox{\hyperlink{statements_try}{try/catch statement}}, if the {\ttfamily {\bfseries throw}} is executed in a \mbox{\hyperlink{statements_try}{try block}}. Otherwise the default system exception handler will be run and the currently running thread will terminate.~\newline
~\newline
 Qore convention dictates that a direct list is thrown with at least two string elements, the error code and a description. All system exceptions have this format.~\newline
~\newline
 See \mbox{\hyperlink{statements_try}{try/catch statements}} for information on how to handle exceptions, and see \mbox{\hyperlink{exception_handling}{Exception Handling}} for information about how throw arguments are mapped to the exception hash.
\end{DoxyParagraph}


 \hypertarget{statements_try}{}\section{try and catch Statements}\label{statements_try}
\begin{DoxyParagraph}{Synopsis}
Some error conditions can only be detected and handled using exception handlers. To catch exceptions, {\ttfamily {\bfseries try}} and {\ttfamily {\bfseries catch}} statements have to be used. When an exception occurs while executing the {\ttfamily {\bfseries try}} block, execution control will immediately be passed to the {\ttfamily {\bfseries catch}} block, which can capture information about the exception.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\bfseries {\ttfamily try}}~\newline
 ~~~~{\itshape \mbox{\hyperlink{statements}{statement}}}~\newline
 {\ttfamily {\bfseries catch} (\mbox{[}\mbox{\hyperlink{data_type_declarations_hash_type}{hash}}\mbox{[}$<$\mbox{\hyperlink{struct_qore_1_1_exception_info}{Exception\+Info}}$>$\mbox{]}\mbox{]} \mbox{[}}{\itshape exception\+\_\+hash\+\_\+variable}{\ttfamily \mbox{]})}~\newline
 ~~~~{\itshape \mbox{\hyperlink{statements}{statement}}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
A single variable can be specified in the catch block to be instantiated with the exception hash, giving information about the exception that has occurred. For detailed information about the exception hash, see \mbox{\hyperlink{exception_handling}{Exception Handling}}.~\newline
~\newline
 If no variable is given in the {\ttfamily {\bfseries catch}} declaration, it will not be possible to access any information about the exception in the {\bfseries {\ttfamily catch}} block. However, the \mbox{\hyperlink{statements_rethrow}{rethrow statement}} can be used to rethrow exceptions at any time in a {\ttfamily {\bfseries catch}} block.
\end{DoxyParagraph}


 \hypertarget{statements_rethrow}{}\section{rethrow Statements}\label{statements_rethrow}
\begin{DoxyParagraph}{Synopsis}
A {\ttfamily {\bfseries rethrow}} statement can be used to rethrow an exception in a {\ttfamily {\bfseries catch}} block. In this case a entry tagged as a rethrow entry will be placed on the exception call stack.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\bfseries {\ttfamily rethrow};} 
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
The rethrown exception will be either passed to the next higher-\/level {\ttfamily {\bfseries catch}} block, or to the system default exception handler, as with a \mbox{\hyperlink{statements_throw}{throw statement}}.~\newline
~\newline
 This statement can be used to maintain coherent call stacks even when exceptions are handled by more than one {\ttfamily {\bfseries catch}} block (for detailed information about the exception hash and the format of call stacks, see \mbox{\hyperlink{exception_handling}{Exception Handling}}).~\newline
~\newline
 Note that it is an error to use the {\ttfamily {\bfseries rethrow}} statement outside of a {\ttfamily {\bfseries catch}} block.
\end{DoxyParagraph}


 \hypertarget{statements_thread_exit}{}\section{thread\+\_\+exit Statements}\label{statements_thread_exit}
\begin{DoxyParagraph}{Synopsis}
{\ttfamily {\bfseries thread\+\_\+exit}} statements cause the current thread to exit immediately. Use this statement instead of the \mbox{\hyperlink{group__library__functions_ga3ec32747f455642fd9ce503094a5cc85}{exit()}} function when only the current thread should exit.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\bfseries {\ttfamily thread\+\_\+exit};} 
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
This statement will cause the current thread to stop executing immediately.
\end{DoxyParagraph}


 \hypertarget{statements_context}{}\section{context Statements}\label{statements_context}
\begin{DoxyParagraph}{Synopsis}
To easily iterate through multiple rows in a hash of arrays (such as a query result set returned by the \mbox{\hyperlink{class_qore_1_1_s_q_l_1_1_datasource_a05b1d0d126d815b2d7578e5ce8b9a0de}{Qore\+::\+S\+Q\+L\+::\+Datasource\+::select()}} or \mbox{\hyperlink{class_qore_1_1_s_q_l_1_1_s_q_l_statement_a204d8637dc5c072ad5e54d6063c25415}{Qore\+::\+S\+Q\+L\+::\+S\+Q\+L\+Statement\+::fetch\+Columns()}} methods), the {\ttfamily {\bfseries context}} statement can be used. Column names can be referred to directly in expressions in the scope of the context statement by preceding the name with a {\ttfamily \char`\"{}\%\char`\"{}} character.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily {\bfseries context}} {\itshape \mbox{[}name\mbox{]}} {\ttfamily (}{\itshape \mbox{\hyperlink{expressions}{data\+\_\+expression}}}{\ttfamily )}~\newline
 ~~~~{\ttfamily \mbox{[}{\bfseries where} (}{\itshape \mbox{\hyperlink{expressions}{where\+\_\+expression}}}{\ttfamily )\mbox{]}}~\newline
 ~~~~{\ttfamily \mbox{[}{\bfseries sort\+By} (}{\itshape \mbox{\hyperlink{expressions}{sort\+\_\+expression}}}{\ttfamily )\mbox{]}}~\newline
 ~~~~{\ttfamily \mbox{[}{\bfseries sort\+Descending\+By} (}{\itshape \mbox{\hyperlink{expressions}{sort\+\_\+descending\+\_\+expression}}}{\ttfamily )\mbox{]}}~\newline
 ~~~~{\itshape \mbox{\hyperlink{statements}{statement}}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
{\itshape \mbox{\hyperlink{expressions}{data\+\_\+expression}}}~\newline
 This must evaluate to a hash of arrays in order for the {\ttfamily {\bfseries context}} statement to execute.~\newline
~\newline
 {\itshape \mbox{\hyperlink{expressions}{where\+\_\+expression}}}~\newline
 An optional {\bfseries {\ttfamily where}} expression may be given, in which case for each row in the hash, the expression will be executed, and if the where expression evaluates to \mbox{\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True}}, the row will be iterated in the context loop. If this expression evaluates to \mbox{\hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False}}, then the row will not be iterated. This option is given so the programmer can create multiple views of a single data structure (such as a query result set) in memory rather than build different data structures by hand (or retrieve the data multiple times from a database).~\newline
~\newline
 {\itshape \mbox{\hyperlink{expressions}{sort\+\_\+expression}}}~\newline
 An optional {\ttfamily {\bfseries sort\+By}} expression may also be given. In this case, the expression will be evaluated for each row of the query given, and then the result set will be sorted in ascending order by the results of the expressions according to the resulting type of the evaluated expression (i.\+e. if the result of the evaluation of the expression gives a string, then string order is used to sort, if the result of the evaluation is an integer, then integer order is used, etc).~\newline
~\newline
 {\itshape \mbox{\hyperlink{expressions}{sort\+\_\+descending\+\_\+expression}}}~\newline
 Another optional modifier to the {\ttfamily {\bfseries context}} statement that behaves the same as above except that the results are sorted in descending order.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
\textcolor{comment}{# note that "%service\_type" and "%effective\_start\_date" represent values}
\textcolor{comment}{# in the service\_history hash of arrays.}
context (service\_history) where (%service\_type == \textcolor{stringliteral}{"voice"})
sortBy (%effective\_start\_date) \{
   \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"%s: start date: %s\(\backslash\)n"}, %msisdn, \mbox{\hyperlink{group__date__and__time__functions_gad5572fcb49964bfe3005e144da579361}{format\_date}}(\textcolor{stringliteral}{"YYYY-MM-DD HH:mm:SS"}, %
      effective\_start\_date));
\}
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxySeeAlso}{See also}

\begin{DoxyItemize}
\item \mbox{\hyperlink{group__context__functions}{Context Functions}}
\item \mbox{\hyperlink{expressions_find}{Find Expressions}}
\item \mbox{\hyperlink{statements_subcontext}{subcontext Statements}}
\item \mbox{\hyperlink{statements_summarize}{summarize Statements}}
\item \mbox{\hyperlink{class_qore_1_1_hash_list_iterator}{Hash\+List\+Iterator}}
\item \mbox{\hyperlink{class_qore_1_1_list_hash_iterator}{List\+Hash\+Iterator}}
\item \mbox{\hyperlink{class_qore_1_1zzz8hashzzz9_aab3d2e6e69d212dbe05de43136f14367}{Qore\+::zzz8hashzzz9\+::context\+Iterator()}}
\end{DoxyItemize}
\end{DoxySeeAlso}


 \hypertarget{statements_summarize}{}\section{summarize Statements}\label{statements_summarize}
\begin{DoxyParagraph}{Synopsis}
{\ttfamily {\bfseries summarize}} statements are like context statements with one important difference\+: results sets are grouped by a {\ttfamily {\bfseries by}} expression, and the statement is executed only once per discrete {\ttfamily {\bfseries by}} expression result. This statement is designed to be used with the \mbox{\hyperlink{statements_subcontext}{subcontext statement}}.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily {\bfseries summarize}} {\ttfamily (}{\itshape \mbox{\hyperlink{expressions}{data\+\_\+expression}}}{\ttfamily ) {\bfseries by} (}{\itshape \mbox{\hyperlink{expressions}{by\+\_\+expression}}}{\ttfamily )}~\newline
 ~~~~{\ttfamily \mbox{[}{\bfseries where} (}{\itshape \mbox{\hyperlink{expressions}{where\+\_\+expression}}}{\ttfamily )\mbox{]}}~\newline
 ~~~~{\ttfamily \mbox{[}{\bfseries sort\+By} (}{\itshape \mbox{\hyperlink{expressions}{sort\+\_\+expression}}}{\ttfamily )\mbox{]}}~\newline
 ~~~~{\ttfamily \mbox{[}{\bfseries sort\+Descending\+By} (}{\itshape \mbox{\hyperlink{expressions}{sort\+\_\+descending\+\_\+expression}}}{\ttfamily )\mbox{]}}~\newline
 ~~~~{\itshape \mbox{\hyperlink{statements}{statement}}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
{\ttfamily {\bfseries summarize}} statements modifiers have the same effect as those for the \mbox{\hyperlink{statements_context}{context statement}}, except for the following\+:~\newline
~\newline
 {\ttfamily {\bfseries by} (}{\itshape \mbox{\hyperlink{expressions}{by\+\_\+expression}}}{\ttfamily )}~\newline
 The {\ttfamily {\bfseries by}} expression is executed for each row in the data structure indicated. The set of unique results defines groups of result rows. For each group of result rows, each row having an identical result of the evaluation of the by expression, the statement is executed only once.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
\textcolor{comment}{# note that "%service\_type" and "%effective\_start\_date" represent values}
\textcolor{comment}{# in the services hash of arrays.}
summarize (services)
    by (%effective\_start\_date)
    where (%service\_type == \textcolor{stringliteral}{"voice"})
    sortBy (%effective\_start\_date) \{
    \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"account has %d service(s) starting on %s\(\backslash\)n"},
           context\_rows(),
           \mbox{\hyperlink{group__date__and__time__functions_gad5572fcb49964bfe3005e144da579361}{format\_date}}(\textcolor{stringliteral}{"YYYY-MM-DD HH:mm:SS"}, %effective\_start\_date));
\}
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxySeeAlso}{See also}

\begin{DoxyItemize}
\item \mbox{\hyperlink{group__context__functions}{Context Functions}}
\item \mbox{\hyperlink{expressions_find}{Find Expressions}}
\item \mbox{\hyperlink{statements_context}{context Statements}}
\item \mbox{\hyperlink{statements_subcontext}{subcontext Statements}}
\item \mbox{\hyperlink{class_qore_1_1_hash_list_iterator}{Hash\+List\+Iterator}}
\item \mbox{\hyperlink{class_qore_1_1_list_hash_iterator}{List\+Hash\+Iterator}}
\end{DoxyItemize}
\end{DoxySeeAlso}


 \hypertarget{statements_subcontext}{}\section{subcontext Statements}\label{statements_subcontext}
\begin{DoxyParagraph}{Synopsis}
Statement used to loop through values within a \mbox{\hyperlink{statements_summarize}{summarize statement}}.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily {\bfseries subcontext}}~\newline
 ~~~~{\ttfamily \mbox{[}{\bfseries where} (}{\itshape \mbox{\hyperlink{expressions}{where\+\_\+expression}}}{\ttfamily )\mbox{]}}~\newline
 ~~~~{\ttfamily \mbox{[}{\bfseries sort\+By} (}{\itshape \mbox{\hyperlink{expressions}{sort\+\_\+expression}}}{\ttfamily )\mbox{]}}~\newline
 ~~~~{\ttfamily \mbox{[}{\bfseries sort\+Descending\+By} (}{\itshape \mbox{\hyperlink{expressions}{sort\+\_\+descending\+\_\+expression}}}{\ttfamily )\mbox{]}}~\newline
 ~~~~{\itshape \mbox{\hyperlink{statements}{statement}}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
The {\ttfamily {\bfseries subcontext}} statement is used in conjunction with \mbox{\hyperlink{statements_summarize}{summarize statements}}. When result rows of a query should be grouped, and then each row in the result set should be individually processed, the Qore programmer should first use a \mbox{\hyperlink{statements_summarize}{summarize statement}}, and then a {\ttfamily {\bfseries subcontext}} statement. The \mbox{\hyperlink{statements_summarize}{summarize statement}} will group rows, and then the nested {\ttfamily {\bfseries subcontext}} statement will iterate through each row in the current summary group.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
summarize (services)
    by (%effective\_start\_date)
    where (%service\_type == \textcolor{stringliteral}{"voice"})
    sortBy (%effective\_start\_date) \{
    \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"account has %d service(s) starting on %s\(\backslash\)n"},
           context\_rows(),
           \mbox{\hyperlink{group__date__and__time__functions_gad5572fcb49964bfe3005e144da579361}{format\_date}}(\textcolor{stringliteral}{"YYYY-MM-DD HH:mm:SS"}, %effective\_start\_date));
    subcontext sortDescendingBy (%effective\_end\_date) \{
        \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"\(\backslash\)tservice %s: ends: %s\(\backslash\)n"}, %msisdn, \mbox{\hyperlink{group__date__and__time__functions_gad5572fcb49964bfe3005e144da579361}{format\_date}}(\textcolor{stringliteral}{"YYYY-MM-DD HH:mm:SS"}, %
      effective\_end\_date));
    \}
\}
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxySeeAlso}{See also}

\begin{DoxyItemize}
\item \mbox{\hyperlink{group__context__functions}{Context Functions}}
\item \mbox{\hyperlink{expressions_find}{Find Expressions}}
\item \mbox{\hyperlink{statements_context}{context Statements}}
\item \mbox{\hyperlink{statements_summarize}{summarize Statements}}
\item \mbox{\hyperlink{class_qore_1_1_hash_list_iterator}{Hash\+List\+Iterator}}
\item \mbox{\hyperlink{class_qore_1_1_list_hash_iterator}{List\+Hash\+Iterator}}
\end{DoxyItemize}
\end{DoxySeeAlso}


 \hypertarget{statements_return}{}\section{return Statements}\label{statements_return}
\begin{DoxyParagraph}{Synopsis}
{\ttfamily {\bfseries return}} statements causes the flow of execution of the function, method or program to stop immediately and return to the caller. This statement can take an optional expression to return a value to the caller as well.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily {\bfseries return}} {\itshape \mbox{\hyperlink{expressions}{\mbox{[}expression\mbox{]}}}};
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
This statement causes execution of the current function, method, or program to returns to the caller, optionally with a return value.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
string sub getName() \{
   \textcolor{keywordflow}{return} \textcolor{stringliteral}{"Barney"};
\}
string name = getName();
\end{DoxyCode}

\end{DoxyParagraph}


 \hypertarget{statements_on_exit}{}\section{on\+\_\+exit Statements}\label{statements_on_exit}
\begin{DoxyParagraph}{Synopsis}
Queues a statement or statement block for unconditional execution when the block is exited, even in the case of exceptions or \mbox{\hyperlink{statements_return}{return statements}}. For similar statement that queue code for execution depending on the exception status when the block exits, see \mbox{\hyperlink{statements_on_success}{on\+\_\+success statements}} and \mbox{\hyperlink{statements_on_error}{on\+\_\+error statements}}.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily {\bfseries on\+\_\+exit}}~\newline
 ~~~~{\itshape \mbox{\hyperlink{statements}{statement}}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
The {\ttfamily {\bfseries on\+\_\+exit}} statement provides a clean way to do exception-\/safe cleanup within Qore code. Any single statment (or statement block) after the {\ttfamily {\bfseries on\+\_\+exit}} keyword will be executed when the current block exits (as long as the statement itself is reached when executing -\/ {\ttfamily {\bfseries on\+\_\+exit}} statements that are never reached when executing will have no effect).~\newline
~\newline
 The position of the {\ttfamily {\bfseries on\+\_\+exit}} statement in the block is important, as the immediate effect of this statement is to queue its code for execution when the block is exited, meaning that {\ttfamily {\bfseries on\+\_\+exit}} statements (along with {\ttfamily {\bfseries on\+\_\+success}} and {\ttfamily {\bfseries on\+\_\+error}} statements) are executed in reverse order respective their declaration when the local scope is exited for any reason, even due to an exception or a \mbox{\hyperlink{statements_return}{return statement}}. Therefore it\textquotesingle{}s ideal for putting cleanup code right next to the code that requires the cleanup.~\newline
~\newline
 Note that if this statement is reached when executing in a loop, the {\ttfamily {\bfseries on\+\_\+exit}} code will be executed for each iteration of the loop.~\newline
~\newline
 By using this statement, programmers ensure that necessary cleanup will be performed regardless of the exit status of the block (exception, \mbox{\hyperlink{statements_return}{return}}, etc).
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
\{
    mutex.lock();
    \textcolor{comment}{# here we queue the unlock of the mutex when the block exits, even if an exception is thrown below}
    on\_exit mutex.unlock();
    \textcolor{keywordflow}{if} (error)
        throw \textcolor{stringliteral}{"ERROR"}, \textcolor{stringliteral}{"Scary error happened"};
    \mbox{\hyperlink{group__string__functions_ga996c5d1686fbc245f0bc7a02012e6a33}{print}}(\textcolor{stringliteral}{"everything's OK!\(\backslash\)n"});
    \textcolor{keywordflow}{return} \textcolor{stringliteral}{"OK"};
\}
\textcolor{comment}{# when the block exits for any reason, the mutex will be unlocked}
\end{DoxyCode}

\end{DoxyParagraph}


 \hypertarget{statements_on_success}{}\section{on\+\_\+success Statements}\label{statements_on_success}
\begin{DoxyParagraph}{Synopsis}
Queues a statement or statement block for execution when the block is exited in the case that no exception is active. Used often in conjunction with the \mbox{\hyperlink{statements_on_error}{on\+\_\+error statement}} and related to the \mbox{\hyperlink{statements_on_exit}{on\+\_\+exit statement}}.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily {\bfseries on\+\_\+success}}~\newline
 ~~~~{\itshape \mbox{\hyperlink{statements}{statement}}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
The {\ttfamily {\bfseries on\+\_\+success}} statement provides a clean way to do block-\/level cleanup within Qore code in the case that no exception is thrown in the block. Any single statment (or statement block) after the {\ttfamily {\bfseries on\+\_\+success}} keyword will be executed when the current block exits as long as no unhandled exception has been thrown (and as long as the statement itself is reached when executing -\/ {\ttfamily {\bfseries on\+\_\+success}} statements that are never reached when executing will have no effect).~\newline
~\newline
 The position of the {\ttfamily {\bfseries on\+\_\+success}} statement in the block is important, as the immediate effect of this statement is to queue its code for execution when the block is exited, meaning that {\ttfamily {\bfseries on\+\_\+success}} statements (along with {\ttfamily {\bfseries on\+\_\+exit}} and {\ttfamily {\bfseries on\+\_\+error}} statements) are executed in reverse order respective their declaration when the local scope is exited for any reason, even due to an exception or a \mbox{\hyperlink{statements_return}{return statement}}. Therefore it\textquotesingle{}s ideal for putting cleanup code right next to the code that requires the cleanup, along with \mbox{\hyperlink{statements_on_error}{on\+\_\+error statements}}, which are executed in a manner similar to {\ttfamily {\bfseries on\+\_\+success}} statements, except {\ttfamily {\bfseries on\+\_\+error}} statements are only executed when there is an active exception when the block is exited.~\newline
~\newline
 Note that if this statement is reached when executing in a loop, the {\ttfamily {\bfseries on\+\_\+success}} code will be executed for each iteration of the loop (as long as there is no active exception).
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
\{
    db.beginTransaction();
    \textcolor{comment}{# here we queue the commit in the case there are no errors}
    on\_success db.commit();
    \textcolor{comment}{# here we queue a rollback in the case of an exception}
    on\_error db.rollback();
    db.select(\textcolor{stringliteral}{"select * from table where id = %v for update"}, id);
    \textcolor{comment}{# .. more code}

    \textcolor{keywordflow}{return} \textcolor{stringliteral}{"OK"};
\}
\textcolor{comment}{# when the block exits. the transaction will be either committed or rolled back,}
\textcolor{comment}{# depending on if an exception was raised or not}
\end{DoxyCode}

\end{DoxyParagraph}


 \hypertarget{statements_on_error}{}\section{on\+\_\+error Statements}\label{statements_on_error}
\begin{DoxyParagraph}{Synopsis}
Queues a statement or statement block for execution when the block is exited in the case that an exception is active. Used often in conjunction with the \mbox{\hyperlink{statements_on_success}{on\+\_\+success statement}} and related to the \mbox{\hyperlink{statements_on_exit}{on\+\_\+exit statement}}.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily {\bfseries on\+\_\+error}}~\newline
 ~~~~{\itshape \mbox{\hyperlink{statements}{statement}}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
The {\ttfamily {\bfseries on\+\_\+error}} statement provides a clean way to do block-\/level cleanup within Qore code in the case that an exception is thrown in the block. Any single statment (or statement block) after the {\ttfamily {\bfseries on\+\_\+error}} keyword will be executed when the current block exits as long as an unhandled exception has been thrown (and as long as the statement itself is reached when executing -\/ {\ttfamily {\bfseries on\+\_\+error}} statements that are never reached when executing will have no effect).~\newline
~\newline
 The position of the {\ttfamily {\bfseries on\+\_\+error}} statement in the block is important, as the immediate effect of this statement is to queue its code for execution when the block is exited, meaning that {\ttfamily {\bfseries on\+\_\+error}} statements (along with {\ttfamily {\bfseries on\+\_\+exit}} and {\ttfamily {\bfseries on\+\_\+error}} statements) are executed in reverse order respective their declaration when the local scope is exited for any reason, even due to an exception or a \mbox{\hyperlink{statements_return}{return statement}}. Therefore it\textquotesingle{}s ideal for putting cleanup code right next to the code that requires the cleanup, along with \mbox{\hyperlink{statements_on_success}{on\+\_\+success statements}}, which are executed in a manner similar to {\ttfamily {\bfseries on\+\_\+error}} statements, except \mbox{\hyperlink{statements_on_success}{on\+\_\+success statements}} are only executed when there is no active exception when the block is exited.~\newline
~\newline
 Note that the code in this statement can only be executed once in any block, as a block (even a block within a loop) can only exit the loop once with an active exception (in contrast to \mbox{\hyperlink{statements_on_success}{on\+\_\+success}} and \mbox{\hyperlink{statements_on_exit}{on\+\_\+exit statements}}, which are executed for every iteration of a loop).
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
\{
    db.beginTransaction();
    \textcolor{comment}{# here we queue the commit in the case there are no errors}
    on\_success db.commit();
    \textcolor{comment}{# here we queue a rollback in the case of an exception}
    on\_error db.rollback();
    db.select(\textcolor{stringliteral}{"select * from table where id = %v for update"}, id);
    \textcolor{comment}{# .. more code}

    \textcolor{keywordflow}{return} \textcolor{stringliteral}{"OK"};
\}
\textcolor{comment}{# when the block exits. the transaction will be either committed or rolled back,}
\textcolor{comment}{# depending on if an exception was raised or not}
\end{DoxyCode}
 
\end{DoxyParagraph}
