---
title: Statements
description: Painless supports all of Java’s  control flow statements except the switch statement. Painless also supports the for in syntax: 
url: https://www.elastic.co/elastic/docs-builder/docs/2413/reference/scripting-languages/painless/painless-statements
products:
  - Painless
---

# Statements
Painless supports all of Java’s [ control flow statements](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/flow.md) except the `switch` statement.

## Conditional statements


### If / Else

```java
if (doc[item].size() == 0) {
  // do something if "item" is missing
} else if (doc[item].value == 'something') {
  // do something if "item" value is: something
} else {
  // do something else
}
```


## Loop statements


### For

Painless also supports the `for in` syntax:
```java
for (def item : list) {
  // do something
}
```

```java
for (item in list) {
  // do something
}
```


### While

```java
while (ctx._source.item < condition) {
  // do something
}
```


### Do-While

```java
do {
  // do something
}
while (ctx._source.item < condition)
```