File tree Expand file tree Collapse file tree 4 files changed +58
-0
lines changed Expand file tree Collapse file tree 4 files changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ const std = @import ("std" );
2
+
3
+ pub fn main () void {
4
+ const a : u8 = 32 ;
5
+ const b : u8 = 128 ;
6
+
7
+ if (a > b ) {
8
+ std .debug .print ("A" , .{});
9
+ } else if (a < b ) {
10
+ std .debug .print ("B" , .{});
11
+ } else {
12
+ std .debug .print ("eq" , .{});
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ const std = @import ("std" );
2
+
3
+ pub fn main () void {
4
+ var a : ? u8 = 32 ;
5
+ check (a );
6
+
7
+ a = null ;
8
+ check (a );
9
+ }
10
+
11
+ fn check (a : ? u8 ) void {
12
+ if (a ) | value | { // Capture
13
+ std .debug .print ("Value: {}\n " , .{value });
14
+ } else {
15
+ std .debug .print ("Value: null\n " , .{});
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ # If Expression
2
+
3
+ ``` bash
4
+ $ zig run basic.zig
5
+ B
6
+ ```
7
+
8
+ ``` bash
9
+ $ zig run ternary.zig
10
+ B
11
+ ```
12
+
13
+ ``` bash
14
+ $ zig run optionan.zig
15
+ Value: 32
16
+ Value: null
17
+ ```
Original file line number Diff line number Diff line change
1
+ const std = @import ("std" );
2
+
3
+ pub fn main () void {
4
+ const a : u8 = 32 ;
5
+ const b : u8 = 128 ;
6
+
7
+ const c = if (a > b ) "A" else "B" ;
8
+
9
+ std .debug .print ("{s}" , .{c });
10
+ }
You can’t perform that action at this time.
0 commit comments