Hi,
I’d like to send a PR to fix the formatting for the instructions in the “Interest is Interesting” exercise.
Under the section " Types under looping" it says " the type of a' is Stringunder the second part of the loop. At runtime, it will never simultaneously hold Int32and String`."
I’d like to fix this formatting mistake. Any objections? If not, I’ll send a PR with the fix.
Thanks!
Not the maintainer, but this text is replicated in the associated concept’s docs so if you get the go-ahead, you’ll want to fix all three places.
crystal/exercises/concept/interest-is-interesting/.docs/introduction.md at 9e6553f76d3479a4d25cc3f66f28912c8c6e2808 · exercism/crystal · GitHub is the line in question.
# 1
# 3
```
## Types under looping
The type of the variable can be different under looping.
In the following example, the type of `a` is `Int32 | String` because it can be `Int32` or `String` under the first part of the loop.
The variable `a` will only carry the type `Int32 | String` in the first part of the loop since when the loop starts, it holds `Int32`, and in the second iteration, it holds a `String`.
This multiple-type system will be explained in detail later.
But since we are sure that the second part of the loop will only hold `String`, the type of `a' is `String` under the second part of the loop.
At runtime, it will never simultaneously hold `Int32` and `String`.
```crystal
i = 0
a = 4
while i < 3
p typeof(a)
# => Int32 | String
a = "4"
p typeof(a)
# 1
# 3
```
## Types under looping
The type of the variable can be different under looping.
In the following example, the type of `a` is `Int32 | String` because it can be `Int32` or `String` under the first part of the loop.
The variable `a` will only carry the type `Int32 | String` in the first part of the loop since when the loop starts, it holds `Int32`, and in the second iteration, it holds a `String`.
This multiple-type system will be explained in detail later.
But since we are sure that the second part of the loop will only hold `String`, the type of `a' is `String` under the second part of the loop.
At runtime, it will never simultaneously hold `Int32` and `String`.
```crystal
i = 0
a = 4
while i < 3
p typeof(a)
# => Int32 | String
a = "4"
p typeof(a)
1 Like
Wow, well-spotted! Maybe the maintainers would like 3 separate pull requests instead of me updating all three files in one go.