So then you either have a formula to find the nth term of the sequence, or, you do a loop and up until n and then print n, which is a slight modification of the loop given.
I don't there's much more we can say to help. Perhaps if he had done his own homework to begin with, instead of snagging someone else's code that he doesn't understand.