Question: I have this for loop that searches a list for specific values and replaces them with new ones. 

```
for (int i = 0; i < Data.Count; i++) {

if (Data[i] > 0 && Data[i] <= 10) {Data[i] = 1;}
else if (Data[i] > 10 && Data[i] < 20) {Data[i] = 2;}      
...
}

```

I've been trying to write this function in linq and I know it can be written this way:

```
var Data2 = Data.Where(x=> x > 0 && x <= 10).Select(y=> y=1).ToList();

```

My question is that is there any way to convert this for loop into linq form without the need to declare new lists? I mean a linq form which searches for these values inside the list and when it finds them it replaces them accordingly.

Answer: 
I would suggest against doing this with LINQ, anyway:

```
Enumerable.Range(0,Data.Count)
          .ForEach(x=>{ 
              if (Data[x] > 0 && Data[x] <= 10) {Data[x] = 1;}
              else if (Data[x] > 10 && Data[i] < 20) {Data[x] = 2;} 
          });

```

this way you don't have to declare a second list, but the code looks less readeable than your original one.
A lot simpler than the other solutions:

```
Data = Data.Select(d => (d / 10) + 1)

```

If you want a top limit, just use `Math.Min((d / 10) + 1, topLimit)` instead.