I imagine it's because totalSongs has a value of six. The while condition in the parenthesis at the beginning is counter <= totalSongs. Each time through the loop you iterate counter: That is, you increase its value by one.
As long as counter isn't a larger value than totalSongs, that loops is gonna repeat. It's your condition.
Can you show us the part of your code where you assign a value to totalSongs?