> For the complete documentation index, see [llms.txt](https://docs.servoy.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/statements.md).

# Statements

## Overview

The `Statements` class provides essential control flow and error-handling structures for JavaScript. It enables managing loops with various conditions, , decision-making and handling errors.

The class also supports declaring variables with `js_flow_var()` and constants with `js_flow_const()`, offering flexibility in managing data within the code.

## Methods Summarized

| Type | Name                                      | Summary                                                                                            |
| ---- | ----------------------------------------- | -------------------------------------------------------------------------------------------------- |
| void | [break()](#break)                         | Break statement exits a loop.                                                                      |
| void | [const()](#const)                         | Constant declaration.                                                                              |
| void | [continue()](#continue)                   | Continue statement, jumps to next iteration of the loop.                                           |
| void | [do while()](#do-while)                   | do while loop                                                                                      |
| void | [for()](#for)                             | for loop                                                                                           |
| void | [for each in()](#for-each-in)             | foreach loop                                                                                       |
| void | [if()](#if)                               | If statement                                                                                       |
| void | [if else()](#if-else)                     | If/Else statement.                                                                                 |
| void | [label()](#label)                         | Provides a statement with an identifier that you can refer to using a break or continue statement. |
| void | [switch()](#switch)                       | Switch statement.                                                                                  |
| void | [try catch()](#try-catch)                 | try/catch statement                                                                                |
| void | [try catch finally()](#try-catch-finally) | try/catch/finally statement                                                                        |
| void | [var()](#var)                             | Variable declaration                                                                               |
| void | [while()](#while)                         | while loop                                                                                         |

## Methods Detailed

### break()

Break statement exits a loop.

**Returns:** void

**Sample**

```js
break
```

### const()

Constant declaration.

**Returns:** void

**Sample**

```js
const #;
```

### continue()

Continue statement, jumps to next iteration of the loop.

**Returns:** void

**Sample**

```js
continue
```

### do while()

do while loop

**Returns:** void

**Sample**

```js
do
{
}
while ( # )
```

### for()

for loop

**Returns:** void

**Sample**

```js
for ( var i = 0 ; i < # ; i++ )
{
}
```

### for each in()

foreach loop

**Returns:** void

**Sample**

```js
for ( var item in obj )
{
}
```

### if()

If statement

**Returns:** void

**Sample**

```js
if ( # )
{
}
```

### if else()

If/Else statement.

**Returns:** void

**Sample**

```js
if ( # )
{
}
else
{
}
```

### label()

Provides a statement with an identifier that you can refer to using a break or continue statement.

For example, you can use a label to identify a loop, and then use the break or continue statements to indicate\
whether a program should interrupt the loop or continue its execution.

**Returns:** void

**Sample**

```js
var i = 0, j;
outer_loop: while (i < 10) {
	i++;
	j = 0;
	while (j < 10) {
		j++;
		if (j > i) continue outer_loop;
		application.output("i=" + i + ", j=" + j);
	}
}
```

### switch()

Switch statement.

**Returns:** void

**Sample**

```js
switch( # )
{
case:
default:
}
```

### try catch()

try/catch statement

**Returns:** void

**Sample**

```js
try
{
	#
}
 catch(#)
{
	#
}
```

### try catch finally()

try/catch/finally statement

**Returns:** void

**Sample**

```js
try
{
	#
}
 catch(#)
{
	#
} finally
{
	#
}
```

### var()

Variable declaration

**Returns:** void

**Sample**

```js
var #;
```

### while()

while loop

**Returns:** void

**Sample**

```js
while ( # )
{
	#
}
```

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.servoy.com/reference/servoycore/dev-api/js-lib/statements.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
