@@ -175,25 +175,7 @@ Using `when` with a subject makes your code easier to read and maintain. When yo
175
175
it also helps Kotlin check that all possible cases are covered. Otherwise, if you don't use a subject with a
176
176
` when ` expression, you need to provide an else branch.
177
177
178
- ## Ranges
179
-
180
- Before talking about loops, it's useful to know how to construct ranges for loops to iterate over.
181
-
182
- The most common way to create a range in Kotlin is to use the ` .. ` operator. For example, ` 1..4 ` is equivalent to ` 1, 2, 3, 4 ` .
183
-
184
- To declare a range that doesn't include the end value, use the ` ..< ` operator. For example, ` 1..<4 ` is equivalent to ` 1, 2, 3 ` .
185
-
186
- To declare a range in reverse order, use ` downTo. ` For example, ` 4 downTo 1 ` is equivalent to ` 4, 3, 2, 1 ` .
187
-
188
- To declare a range that increments in a step that isn't 1, use ` step ` and your desired increment value.
189
- For example, ` 1..5 step 2 ` is equivalent to ` 1, 3, 5 ` .
190
-
191
- You can also do the same with ` Char ` ranges:
192
-
193
- * ` 'a'..'d' ` is equivalent to ` 'a', 'b', 'c', 'd' `
194
- * ` 'z' downTo 's' step 2 ` is equivalent to ` 'z', 'x', 'v', 't' `
195
-
196
- ## Conditional expressions and ranges practice
178
+ ## Conditional expressions practice
197
179
198
180
### Exercise 1 {initial-collapse-state="collapsed" collapsible="true" id="conditional-expressions-exercise-1"}
199
181
@@ -281,6 +263,24 @@ fun main() {
281
263
```
282
264
{initial-collapse-state="collapsed" collapsible="true" collapsed-title="Example solution" id="kotlin-tour-control-flow-conditional-solution-2"}
283
265
266
+ ## Ranges
267
+
268
+ Before talking about loops, it's useful to know how to construct ranges for loops to iterate over.
269
+
270
+ The most common way to create a range in Kotlin is to use the ` .. ` operator. For example, ` 1..4 ` is equivalent to ` 1, 2, 3, 4 ` .
271
+
272
+ To declare a range that doesn't include the end value, use the ` ..< ` operator. For example, ` 1..<4 ` is equivalent to ` 1, 2, 3 ` .
273
+
274
+ To declare a range in reverse order, use ` downTo. ` For example, ` 4 downTo 1 ` is equivalent to ` 4, 3, 2, 1 ` .
275
+
276
+ To declare a range that increments in a step that isn't 1, use ` step ` and your desired increment value.
277
+ For example, ` 1..5 step 2 ` is equivalent to ` 1, 3, 5 ` .
278
+
279
+ You can also do the same with ` Char ` ranges:
280
+
281
+ * ` 'a'..'d' ` is equivalent to ` 'a', 'b', 'c', 'd' `
282
+ * ` 'z' downTo 's' step 2 ` is equivalent to ` 'z', 'x', 'v', 't' `
283
+
284
284
## Loops
285
285
286
286
The two most common loop structures in programming are ` for ` and ` while ` . Use ` for ` to iterate over a range of
0 commit comments