Initialize instance variable in loop

why can not initialize instance variable in a loop contained in construct function

Well it really depends on what are you exactly doing. An example would be great:

  • If you meant that: you cannot initialize instance variable from within the class constructor. Then the only reason I can think of is that the variable is final and compiler cannot assure that it will be assigned only once - using helper variable will suffice
  • If you meant that: you cannot initialize a instance variable from a loop contained within a closure within constructor. This is the case only when the variable is final. The loop is irrelevant here. The reason would be that the code is located within a closure, which may be launched from anywhere - but final variable initialization is only allowed from class constructor.

@jbytecoder thanks for detailed explain. It really help. my case is covered by your option 1