This content is archived!For the 2018-2019 school year, we have switched to using the WLMOJ judge for all MCPT related content. This is an archive of our old website and will not be updated.
The following provides an overview of counted loops:
The following example will make the use of these loops clearer. Let’s say we wanted to print
Hello World! 5 times. We could accomplish this as follows:
But, what if we wanted to increment by a number other than one? For example, to output all the multiples of 3 from 1 to 14, we could iterate from 1 to 14 and use conditionals to check for multiplicity. However, we can achieve the same result using loops as follows. (We know that the first number will be 3)
Use counted loops to output a 5 by 5 times table as follows: