The clo­sure loop­ing prob­lem

OpenSource For You - - LET'S TRY DEVELOPERS -

vou should be very care­ful while deal­ing with loops within the clo­sure. Con­sider the ex­am­ple shown be­low:

In the above code, for ev­ery it­er­a­tion of‘i’ a new clo­sure will be cre­ated. So now if funcs[0] tries to ac­cess the value of ‘i’ it will get zero. The same holds for the funcs[1] and funcs[2] , and hence you will get your ex­pected out­put.

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.