Index out of range while loop

I’m getting an index out of range error at line 16.
lineLength = lineLength + charactersLength[i]

I thought that it wouldn’t get out of range because of the while loop with a break. Am I doing something wrong?

Enable Python support and load DesignScript library

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

charactersLength = IN[0]
lineMaxLength= IN[1]
lineLength = 0.0
lineNumber = 0
i = 0

while i < len(charactersLength):
	if i == len(charactersLength):
		break
	while lineLength < lineMaxLength:
		lineLength = lineLength + charactersLength[i]
		i = i + 1
	else:
		lineNumber = lineNumber + 1
		lineLength = 0.0
	

OUT = lineNumber

I realized that I think the nested while could run once after it gets out of range so i copied the break in there as well. I don’t know if having two breaks is overkill but its running.

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

charactersLength = IN[0]
lineMaxLength= IN[1]
lineLength = 0.0
lineNumber = 0
i = 0

while i < len(charactersLength):
	if i == len(charactersLength):
		break
	while lineLength < lineMaxLength:
		if i == len(charactersLength):
			break
		lineLength = lineLength + charactersLength[i]
		i = i + 1
	else:
		lineNumber = lineNumber + 1
		lineLength = 0.0
	

OUT = lineNumber