creating final variables inside a loop

Yes, it is allowed. The final keyword means that you can’t change the value of the variable within its scope. For your loop example, you can think of the variable going out of scope at the bottom of the loop, then coming back into scope with a new value at the top of the loop. Assigning to the variable within the loop won’t work.

Leave a Comment