# Step Count Algorithm in LMC Count-controlled loops are used in many programs to increment a counter for each iteration of the loop. Per default the increment for the counter is +1.

```FOR counter FROM 1 TO 10:
OUTPUT (COUNTER)```

However you can specify a different step when incrementing your counter in a count-controlled loop. For instance to count in 5:

```FOR counter FROM 0 TO 100 STEP 5:
OUTPUT (COUNTER)```

You can also use different starting and ending values:

```FOR counter FROM 50 TO 250 STEP 5:
OUTPUT (COUNTER)```

A negative step can also be used to decrement the counter:

```FOR counter FROM 20 TO 0 STEP -2:
OUTPUT (COUNTER)```

This challenge consists of writing a program using LMC to implement a count-controlled loop using a step defined by the end user. Your program will:

• INPUT: Retrieve the starting value for the step count algorithm from the end user.
• INPUT: Retrieve the ending value for the for step count algorithm from the end user.
• INPUT: Retrieve the step value from the end user.
• Count and output all the values (from the starting value to the ending value, using the given step).

Note that this algorithm is an implementation of an arithmetic number sequence.

To complete this challenge you will need to use one of the following online LMC Simulators:

The list of LMC instructions is provided at the bottom of this page.

You will be able to test your algorithm using the following input values:

 Test # Input Values Expected Output Pass/Fail #1 Start Value: 10End Value: 20Step: 2 10,12,14,16,18,20 #2 Start Value: 82End Value: 100Step: 5 82,87,92,97 #3 Start Value: 10End Value: 1Step: -1 10,9,8,7,6,5,4,3,2,1

#### LMC Instruction Set

Note that in the following table “xx” refers to a memory address (aka mailbox) in the RAM. The online LMC simulator has 100 different mailboxes in the RAM ranging from 00 to 99.

Did you like this challenge?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 3

No votes so far! Be the first to rate this post.

As you found this challenge interesting...