@@ -1305,6 +1305,12 @@ kw";"
1305
1305
1306
1306
Short-circuiting boolean AND.
1307
1307
1308
+ This is equivalent to `x ? y : false`: it returns `false` if `x` is `false` and the result of evaluating `y` if `x` is `true`.
1309
+ Note that if `y` is an expression, it is only evaluated when `x` is `true`, which is called "short-circuiting" behavior.
1310
+
1311
+ Also, `y` does not need to have a boolean value. This means that `(condition) && (statement)` can be used as shorthand for
1312
+ `if condition; statement; end` for an arbitrary `statement`.
1313
+
1308
1314
See also [`&`](@ref), the ternary operator `? :`, and the manual section on [control flow](@ref man-conditional-evaluation).
1309
1315
1310
1316
# Examples
@@ -1316,6 +1322,9 @@ true
1316
1322
1317
1323
julia> x < 0 && error("expected positive x")
1318
1324
false
1325
+
1326
+ julia> x > 0 && "not a boolean"
1327
+ "not a boolean"
1319
1328
```
1320
1329
"""
1321
1330
kw " &&"
@@ -1325,6 +1334,12 @@ kw"&&"
1325
1334
1326
1335
Short-circuiting boolean OR.
1327
1336
1337
+ This is equivalent to `x ? true : y`: it returns `true` if `x` is `true` and the result of evaluating `y` if `x` is `false`.
1338
+ Note that if `y` is an expression, it is only evaluated when `x` is `false`, which is called "short-circuiting" behavior.
1339
+
1340
+ Also, `y` does not need to have a boolean value. This means that `(condition) || (statement)` can be used as shorthand for
1341
+ `if !(condition); statement; end` for an arbitrary `statement`.
1342
+
1328
1343
See also: [`|`](@ref), [`xor`](@ref), [`&&`](@ref).
1329
1344
1330
1345
# Examples
@@ -1334,6 +1349,9 @@ true
1334
1349
1335
1350
julia> false || true || println("neither is true!")
1336
1351
true
1352
+
1353
+ julia> pi < 3 || "not a boolean"
1354
+ "not a boolean"
1337
1355
```
1338
1356
"""
1339
1357
kw " ||"
0 commit comments