You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: concepts/conditionals/about.md
+13-11Lines changed: 13 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ Here is a list of the operators and an example of when they give a `true` value:
17
17
18
18
| Method | Description | Example |
19
19
| ------ | --------------------- | ------- |
20
-
| < | less than |5 < 4|
20
+
| < | less than |4 < 5|
21
21
| <= | less than or equal | 4 <= 4 |
22
22
| > | greater than | 3 > 1 |
23
23
| >= | greater than or equal | 2 >= 2 |
@@ -66,7 +66,7 @@ end
66
66
67
67
## Unless statement
68
68
69
-
The `unless`unless statement works very similarly to the `if` statement but it will run the code inside the `unless` statement if the condition is falsey.
69
+
The `unless` statement works very similarly to the `if` statement but it will run the code inside the `unless` statement if the condition is falsey.
70
70
71
71
```ruby
72
72
value =1
@@ -83,8 +83,8 @@ end
83
83
84
84
## Else statement
85
85
86
-
The `else` statement can be used in conjunction with the `if`and `unless` statements.
87
-
The `else` statement will be executed if the `if` branch or the `unless` branch is not executed.
86
+
The `else` statement can be used in conjunction with the `if`statement.
87
+
The `else` statement will be executed if the `if` branch is not executed.
88
88
89
89
```ruby
90
90
value =1
@@ -95,29 +95,31 @@ else
95
95
end
96
96
# => "1 is equal to 1"
97
97
98
-
unless value <2
98
+
if value >2
99
+
"1 is greater than 2"
100
+
else
99
101
"1 is not greater than 2"
100
102
end
101
-
# => "1 is greater than 2"
103
+
# => "1 is not greater than 2"
102
104
```
103
105
104
106
## "Cascading-if" statements
105
107
106
108
The `elsif` statement can be used in conjunction with the if statement.
107
109
The `elsif` statement will be executed if the if branch is not executed and the condition of the elsif statement is truthy.
108
110
Elsif statements can be chained together and the first truthy condition will be executed.
109
-
There can also be an else statement at the end of the if statement which will run if non of the earlier statement has been true.
111
+
There can also be an else statement at the end of the if statement which will run if none of the earlier statements have been true.
110
112
111
113
```ruby
112
114
value =1
113
-
if value !=1
114
-
"1 is not equal to 1"
115
+
if value ==0
116
+
"1 is equal to 0"
115
117
elsif value >2
116
118
"1 is greater than 2"
117
119
else
118
-
"1 is not equal to 1 and 1 is not greater than 2"
120
+
"1 is not equal to 0 and 1 is not greater than 2"
119
121
end
120
-
# => "1 is not equal to 1 and 1 is not greater than 2"
122
+
# => "1 is not equal to 0 and 1 is not greater than 2"
Copy file name to clipboardExpand all lines: concepts/conditionals/introduction.md
+13-11Lines changed: 13 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ Here is a list of the operators and an example of when they give a `true` value:
17
17
18
18
| Method | Description | Example |
19
19
| ------ | --------------------- | ------- |
20
-
| < | less than |5 < 4|
20
+
| < | less than |4 < 5|
21
21
| <= | less than or equal | 4 <= 4 |
22
22
| > | greater than | 3 > 1 |
23
23
| >= | greater than or equal | 2 >= 2 |
@@ -53,7 +53,7 @@ end
53
53
54
54
## Unless statement
55
55
56
-
The `unless`unless statement works very similarly to the `if` statement but it will run the code inside the `unless` statement if the condition is falsey.
56
+
The `unless` statement works very similarly to the `if` statement but it will run the code inside the `unless` statement if the condition is falsey.
57
57
58
58
```ruby
59
59
value =1
@@ -70,8 +70,8 @@ end
70
70
71
71
## Else statement
72
72
73
-
The `else` statement can be used in conjunction with the `if`and `unless` statements.
74
-
The `else` statement will be executed if the `if` branch or the `unless` branch is not executed.
73
+
The `else` statement can be used in conjunction with the `if`statement.
74
+
The `else` statement will be executed if the `if` branch is not executed.
75
75
76
76
```ruby
77
77
value =1
@@ -82,29 +82,31 @@ else
82
82
end
83
83
# => "1 is equal to 1"
84
84
85
-
unless value <2
85
+
if value >2
86
+
"1 is greater than 2"
87
+
else
86
88
"1 is not greater than 2"
87
89
end
88
-
# => "1 is greater than 2"
90
+
# => "1 is not greater than 2"
89
91
```
90
92
91
93
## "Cascading-if" statements
92
94
93
95
The `elsif` statement can be used in conjunction with the if statement.
94
96
The `elsif` statement will be executed if the if branch is not executed and the condition of the elsif statement is truthy.
95
97
Elsif statements can be chained together and the first truthy condition will be executed.
96
-
There can also be an else statement at the end of the if statement which will run if non of the earlier statement has been true.
98
+
There can also be an else statement at the end of the if statement which will run if none of the earlier statements have been true.
97
99
98
100
```ruby
99
101
value =1
100
-
if value !=1
101
-
"1 is not equal to 1"
102
+
if value ==0
103
+
"1 is equal to 0"
102
104
elsif value >2
103
105
"1 is greater than 2"
104
106
else
105
-
"1 is not equal to 1 and 1 is not greater than 2"
107
+
"1 is not equal to 0 and 1 is not greater than 2"
106
108
end
107
-
# => "1 is not equal to 1 and 1 is not greater than 2"
109
+
# => "1 is not equal to 0 and 1 is not greater than 2"
0 commit comments