<commit_before>[[painless-statements]]
=== Statements

Painless supports all of Java's https://docs.oracle.com/javase/tutorial/java/nutsandbolts/flow.html[
control flow statements] except the `switch` statement.

==== Conditional statements

===== If / Else

[source,painless]
---------------------------------------------------------
if (doc[item].size() == 0) {
  // do something if "item" is missing
} else {
  // do something else
}
---------------------------------------------------------

==== Loop statements

===== For

Painless also supports the `for in` syntax from Groovy:

[source,painless]
---------------------------------------------------------
for (item : list) {
  ...
}
---------------------------------------------------------<commit_msg>[DOCS] Correct `for in` example in Painless docs (#49991)<commit_after>[[painless-statements]]
=== Statements

Painless supports all of Java's https://docs.oracle.com/javase/tutorial/java/nutsandbolts/flow.html[
control flow statements] except the `switch` statement.

==== Conditional statements

===== If / Else

[source,painless]
---------------------------------------------------------
if (doc[item].size() == 0) {
  // do something if "item" is missing
} else {
  // do something else
}
---------------------------------------------------------

==== Loop statements

===== For

Painless also supports the `for in` syntax from Groovy:

[source,painless]
---------------------------------------------------------
for (def item : list) {
  ...
}
---------------------------------------------------------
{'fraction_non_alphanumeric': 0.4016602809706258, 'fraction_numerical': 0.004469987228607918, 'mean_word_length': 1.324925816023739, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5010645', 'n_tokens_mistral': 405, 'n_tokens_neox': 362, 'n_words': 107}