That's due to While function and it does not stop right after the last vertice.
It would be much better to use your certain Mleader style then you know the number of vertices required to ask the user to specify in prior of setting the field value to it, otherwise it would be much professional way to get the number of vertices that the current mleader style uses then you modify your codes and use something like repeat ( based on the number of vertices ) then finally set the text string < field > .