string[] letters = new string[] {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
List<string> AlphabeticalUnits = new List<string>();
private string lastUnit = "ZZ";
void Awake()
{
bool stopGenerating = false;
int firstLetterUnit = 0, secondLetterUnit = 0, endlessLoopSafeguard = 0, loopLimit = 729;
string newUnit;
while (!stopGenerating)
{
newUnit = letters[firstLetterUnit] + letters[secondLetterUnit];
AlphabeticalUnits.Add(newUnit);
secondLetterUnit++;
if (secondLetterUnit > letters.Length)
{
firstLetterUnit++;
secondLetterUnit = 0;
}
if (newUnit == lastUnit || endlessLoopSafeguard >= loopLimit) {stopGenerating = true;}
}
}
The error happens when secondLetterUnit reaches 26, at which point it's supposed to go back to 0 and add 1 to firstLetterUnit but i get an IndexOutOfRangeException