I run into this often during programming where I want to have a loop count index inside of a foreach and have to create an integer, use it, increment, etc. Wouldn't it be a good idea if there was a keyword introduced that was the loop count inside of a foreach? It could also be used in other loops as well.
Does this go against the use of keywords seeing as how the compiler would not allow this keyword used anywhere but in a loop construct?
Best Answer
If you need a loop count inside a
foreach
loop why don't you just use a regularfor
loop. Theforeach
loop was intended to make specific uses offor
loops simpler. It sounds like you have a situation where the simplicity of theforeach
is no longer beneficial.