Calculate sequence lenght before entry into the loop