Solution: Types of Loops
Let's discuss the solution of the exercise.
We'll cover the following
Problem
In this exercise, a target number is given for counting up or down to. Write a piece of code that prints this counting in the following manner:
- If the
number
is5
and the value ofoptionSelected
isUp
, the output should be from0
–5
as follows:
Counting Up: 0
Counting Up: 1
Counting Up: 2
Counting Up: 3
Counting Up: 4
Counting Up: 5
- If the
number
is3
and the value ofoptionSelected
isDown
, the output should be from3
–0
as follows:
Counting Down: 3
Counting Down: 2
Counting Down: 1
Counting Down: 0
Get hands-on with 1400+ tech skills courses.