<div dir="ltr"><div>I'm participating in Advent of Code 2023 using Java.  It reminds me how I frequently wish I could have an index in a modern for loop without having to resort to using the old/traditional for loop.  Now that the JEP 456 Unnamed Variables & Patterns is progressing nicely I can see how it could be used implicitly to grant my wish.</div><div><br></div><div>Instead of writing:</div><div><br></div><div>final String[] strings = getSomeStrings();<br></div><div>int index = 0;</div><div>for (final String str : strings)</div><div>{</div><div>  // use the str and the index<br></div><div>  index++;</div><div>}</div><div><br></div><div>and risking the chance I may forget to place the index++ ... I would rather have something like:</div><div><br></div><div><div>final String[] strings = getSomeStrings();<br></div>for (int index, final String str : strings)<div>{</div><div>  // use the str and the index<br></div>}<div><br></div><div>where the new part "int index" is optional, and the compiler could treat it like "int _" if not specified.  Of course it could also be long, one assumes.<br></div><div><br></div><div>I do realize it's merely syntactic sugar and I do know how to write the code I need, but it does surprise me the number of times I end up writing old for loops simply because I could use the index, but otherwise know doing it the modern way is cleaner and more expressive, if only I had the index too.<br></div></div></div>