The for loop makes no sense

Can someone explain how you would know to set up the for loop constraint in the solution below:
(str.length - wordsCount * wordLength) + 1

Because i is the start index of a window containing all words, the last possible i would be the length of s minus the length of all words. It helps to optimize a bit, not significant to impact the complexity tho.