Skip to content

Commit

Permalink
[DOCS] Update painless statements with if/else example (#47485)
Browse files Browse the repository at this point in the history
  • Loading branch information
renshuki authored and jrodewig committed Oct 3, 2019
1 parent be397b7 commit 2288052
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion docs/painless/painless-lang-spec/painless-statements.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,28 @@
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) {
...
}
---------------------------------------------------------
---------------------------------------------------------

0 comments on commit 2288052

Please sign in to comment.