backendgym backendgym · reps Sign in with GitHubSign in

02Two loops, one difference

csharp-reading / reps/02/README.md

Read Program.cs first, then run it: dotnet run --project reps/02. It prints:

for:     3,3,3
foreach: 0,1,2

Most readers expect 0,1,2 twice; some, burned once, expect 3,3,3 twice.

After the rep
  1. 1 How many i variables do the two loops create, and how many n? Answer that and both lines follow.
  2. 2 foreach hasn't always behaved like this. When did it change, and what does that mean for code written before then?