From dc02868671c2ce3ba5a1b6e9a9e1ccf59919f944 Mon Sep 17 00:00:00 2001 From: Francois-Clement Brossard Date: Fri, 4 Oct 2019 04:22:48 +0900 Subject: [PATCH] [DOCS] Update painless statements with if/else example (#47485) --- .../painless-statements.asciidoc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/painless/painless-lang-spec/painless-statements.asciidoc b/docs/painless/painless-lang-spec/painless-statements.asciidoc index 3bc4513baa7..b9aceed9cf0 100644 --- a/docs/painless/painless-lang-spec/painless-statements.asciidoc +++ b/docs/painless/painless-lang-spec/painless-statements.asciidoc @@ -4,6 +4,23 @@ 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] @@ -11,4 +28,4 @@ Painless also supports the `for in` syntax from Groovy: for (item : list) { ... } ---------------------------------------------------------- \ No newline at end of file +---------------------------------------------------------