File tree 1 file changed +32
-0
lines changed
book/src/02_basic_calculator
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,38 @@ if number < 5 {
36
36
}
37
37
```
38
38
39
+ ### ` else if ` clauses
40
+
41
+ Your code drifts more and more to the right when you have multiple ` if ` expressions, one nested inside the other.
42
+
43
+ ``` rust
44
+ let number = 3 ;
45
+
46
+ if number < 5 {
47
+ println! (" `number` is smaller than 5" );
48
+ } else {
49
+ if number >= 3 {
50
+ println! (" `number` is greater than or equal to 3, but smaller than 5" );
51
+ } else {
52
+ println! (" `number` is smaller than 3" );
53
+ }
54
+ }
55
+ ```
56
+
57
+ You can use the ` else if ` keyword to combine multiple ` if ` expressions into a single one:
58
+
59
+ ``` rust
60
+ let number = 3 ;
61
+
62
+ if number < 5 {
63
+ println! (" `number` is smaller than 5" );
64
+ } else if number >= 3 {
65
+ println! (" `number` is greater than or equal to 3, but smaller than 5" );
66
+ } else {
67
+ println! (" `number` is smaller than 3" );
68
+ }
69
+ ```
70
+
39
71
## Booleans
40
72
41
73
The condition in an ` if ` expression must be of type ` bool ` , a ** boolean** .\
You can’t perform that action at this time.
0 commit comments