Coding Exercise: Types of Loops

Let's test your skills with loops.

We'll cover the following

Problem

In this exercise, a target number is given to count up or down to. Write a piece of code that prints this counting in the following manner:

  • If the number is 5 and the value of optionSelected is Up, the output should be from 05 as follows:
Counting Up: 0
Counting Up: 1
Counting Up: 2
Counting Up: 3
Counting Up: 4
Counting Up: 5
  • If the number is 3 and the value of optionSelected is Down, the output should be from 30 as follows:
Counting Down: 3
Counting Down: 2
Counting Down: 1
Counting Down: 0

Sample input

The program accepts accept one string and one int parameter, for example:

"Up", 2

Expected output

The finished output of the program should look like the example below:

Counting Up: 0
Counting Up: 1
Counting Up: 2

Get hands-on with 1200+ tech skills courses.