Yes, well, the error pretty much tells you what you need to know: you can't do that. And you've already found alternate ways to do the same thing you were trying to do. They don't want you to repeat the "int" part of the declaration because if you did that, you could also write a loop that declares an int and a String, for example. Not that this is inherently wrong
, necessarily, but the language designers made a conscious choice to limit how much complexity you are allowed to put into a single for statement. They allow more than one variable to be initialized, only if the variables are of the same type - and in that case, they can share the type declaration (the word
"int" in this case); you don't have to repeat it.