for (int yearIndex = 0; yearIndex < totalYears; yearIndex++)You need to write the line like this:
for (int yearIndex = 0; yearIndex < totalYears; yearIndex++)Then you can break on yearIndex++ which is the the statement that is executed right after the last line inside the for loop.