The meaning of setlocal is to localize variables. When it encounters the first endlocal statement, it ends this localization process. So, if defined inside for (), if the endlocal statement is not added in the appropriate position, the setlocal enabledelayedexpansion statement will always take effect.
In addition, more than 32 levels of setlocal statements will generate the error "The maximum setlocal recursion level has been reached". And one of the means to solve this problem is to use the endlocal statement to end the variable localization process before executing the 33rd setlocal statement.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。