Thank you Arocnies for your guidance. However for a newbee like me no book/tutorial mentions that you don’t need to specify. No one taks about it and thus confusion. However, i saw some C# code and there also it was explicitly declared.
My guess is that val in for would be just redundant. for syntax implies that we define a variable there. The same for function arguments - we don’t do it like this
fun foo(val param1: String, val param2: String)
(I assume you meant the opposite: it is val, not var)
Because changing its value doesn’t make too much sense. Once again, this is similar to function parameters. We received some value from someone and even if we modify it, then with new function call / loop iteration we will just get another value.
Also, this is not really counter. Remember that for in Kotlin isn’t based on counters, but on iterators (well, in some cases they are actually optimized by the compiler to use counters). If you need counters then use while.