Please show the code that you have done so far and we can point out how to correct it.
Without that, we can only give you general tips, that you probably already know. Like:
To end a loop, just use 'break'.
Or just use "for(int i = 0; i < 10; i++){...}" that will end automatically after 10 steps.