Asdfkbaf aklsnfanf asklfnhlaks

fnklasfnc aslknfalknf lkasdnflka

I would just write a lot of loops. How would you write a function that loops from first parameter to the second parameter, logging out the numbers. Could you make it so it knew how to work in either direction, if one was bigger than the other? Have you done the fizz-buzz problem? How about a loop that lists every date (day and month in a year). Could you do it with just two nested loops by using a clever data structure? Could you have it show the work week too? And the day of the week? And the day of the year (1-365)? Just come up with problems. How about a sudoku checker? Not a solver, but just to check if it is a valid sudoku matrix. What about a times table or addition table? Could you count all the numbers whose digits add up to 7 between 1 and 1,000,000? Could you parameterize it so that the two numbers are passed in so could be anything?

Do some googling for looping algorithms. There are some here. It appears to be written in Python, but that’s OK. The algorithm is what’s important, not the language. See if you can solve them without looking at the code. Use the code as a hint if you need it.

A lot of simply algorithm challenges involving string and array manipulation involve loops. A lot of the mathematical ones do too. See if you can find some. There are a lot of sites out there offering algorithm challenges.


Best way to practise loops is to write tons of them, by doing challenges or projects that require you to iterate through arrays or perform repeated computation until a condition is met.

I’d start by trying to memorise the syntax of the 3 loops:
For -> While -> Do While

Then apply them and repeat the process countless of times until you get it down. Here’s a couple of exercises:

  • Log the numbers from 0 to 10
  • … from 10 to 0
  • Print all multiplication tables from 1 to 10 using a nested for loop
  • Create an array of elements and log the elements
  • Create an array of arrays (matrix) with numbers and log them all (using a nested for loop)
  • Do all of the previous challenges but using a while loop

In the same boat with @kevinSmith and @luishendrix92 about practicing to write more loops. Programming language is a language. One of the best way to learn a language is to speak it with another people (in this case, the computer).