On Wednesday, 1 March 2023 at 19:05:10 UTC, DLearner wrote:
```
Error: variable `wk_Idx` is shadowing variable
`for3.main.wk_Idx`
```
Why is this usage wrong?
Or use the `each` template which is almost the same as `foreach`
to avoid the shadowing variable issue.
```d
import std.algorithm,
On Wednesday, 1 March 2023 at 19:05:10 UTC, DLearner wrote:
(1) & (2) compile and run with the expected results.
But (3) fails with:
```
Error: variable `wk_Idx` is shadowing variable
`for3.main.wk_Idx`
```
Why is this usage wrong?
With `foreach`, you can't reuse an existing variable as the l
Hi
Please consider (1):
```
void main() {
import std.stdio;
int wk_Idx;
int[2] IntArr;
IntArr[0] = 1;
IntArr[1] = 2;
for (wk_Idx = 0; wk_Idx <= 1; wk_Idx = wk_Idx + 1) {
writeln("wk_Idx = ", wk_Idx, " IntArr = ", IntArr[wk_Idx]);
}
}
```
Now consider (2), which is