I have an explaination for your code.
Your code makes sqaures indeed but what happens is that when the last square is made(i = 7 ; 7 * 7= 49) the loop will stop because j is over 40.
If you want to...