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:
Turing
Python
Java
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:
Turing
Python
Java
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)
Turing
Python
Java
Practice
Use counted loops to output a 5 by 5 times table as follows:
1 | 2 | 3 | 4 | 5 |
2 | 4 | 6 | 8 | 10 |
3 | 6 | 9 | 12 | 15 |
4 | 8 | 12 | 16 | 20 |
5 | 10 | 15 | 20 | 25 |