OpenSearch/docs/painless/painless-lang-spec/painless-statements.asciidoc
James Rodewig 322dabe3de [DOCS] Correct for in example in Painless docs (#49991)
Adds a needed `def` keyword to the `for in` example in the Painless docs.
2019-12-09 11:05:12 -05:00

32 lines
737 B
Plaintext

[[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) {
...
}
---------------------------------------------------------