authorgravatar for mateusz.okulus@protonmail.comMateuszOkulus <mateusz.okulus@protonmail.com> 2019-12-28 16:59:47+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-28 14:26:10-05:00
log6c3ccea29b2034654558a0b8e839a4a5ee84c57f
tree9fec9c754b35eb035e62ee83ab58fa89b96c8025
parent25e71216c4640a3d88c8f63912ea574ad6fa004c

Make it more obvious that ifs are expressions


1 files changed, 8 insertions(+), 4 deletions(-)

doc/langref.html.in+8-4
...@@ -3714,6 +3714,14 @@ fn typeNameLength(comptime T: type) usize {...@@ -3714,6 +3714,14 @@ fn typeNameLength(comptime T: type) usize {
37143714
3715const assert = @import("std").debug.assert;3715const assert = @import("std").debug.assert;
37163716
3717test "if expression" {
3718 // If expressions are used instead of a ternary expression.
3719 const a: u32 = 5;
3720 const b: u32 = 4;
3721 const result = if (a != b) 47 else 3089;
3722 assert(result == 47);
3723}
3724
3717test "if boolean" {3725test "if boolean" {
3718 // If expressions test boolean conditions.3726 // If expressions test boolean conditions.
3719 const a: u32 = 5;3727 const a: u32 = 5;
...@@ -3725,10 +3733,6 @@ test "if boolean" {...@@ -3725,10 +3733,6 @@ test "if boolean" {
3725 } else {3733 } else {
3726 unreachable;3734 unreachable;
3727 }3735 }
3728
3729 // If expressions are used instead of a ternary expression.
3730 const result = if (a != b) 47 else 3089;
3731 assert(result == 47);
3732}3736}
37333737
3734test "if optional" {3738test "if optional" {