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 8a77712 commit f5ecfa4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion docs/painless/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 f5ecfa4

Please sign in to comment.