From f8fefb44b08d547c957098942cbb6c3b6ead43cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sun, 20 Mar 2022 21:23:45 +0100 Subject: [PATCH] add an example that conditional statements return a value --- ch02.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ch02.jl b/ch02.jl index 2c58608..9546ea4 100644 --- a/ch02.jl +++ b/ch02.jl @@ -146,6 +146,20 @@ end x = -7 x > 0 ? println("x is positive") : println("x is not positive") +# Code showing that conditional statements return a value + +x = -4.0 +y = if x > 0 + sqrt(x) + else + sqrt(-x) + end +y + +x = 9.0 +y = x > 0 ? sqrt(x) : sqrt(-x) +y + # Code from listing 2.4 for i in [1, 2, 3]