Stop for loop if number of characters is exceeded