Challenge: Designing a NumberRange Struct
A coding challenge based on the concepts covered in this chapter.
We'll cover the following
Problem statement
Design a struct
that works similarly to NumberRange
, which also supports specifying the step size. The step size can be the third member:
Sample input
foreach (element; NumberRange(0, 10, 2)) {
write(element, ' ');
}
Sample output
The expected output of the code above is every second number from 0 to 10:
0 2 4 6 8
Challenge
This problem is designed for you to practice, so try to solve it on your own first. If you get stuck, you can always refer to the explanation and solution provided in the next lesson. Good luck!
Get hands-on with 1400+ tech skills courses.