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.
The exact equivalent would be:

```
Data
  .Select((e,i) => new { Element = e, Index = i })
  .Where(ei => ei.Element > 0 && ei.Element < 20)
  .ToList()
  .ForEach(ei => Data[ei.Index] = (ei.Element <= 10) ? 1 : 2);

```

or second possibility: look at [Save](https://stackoverflow.com/questions/18427812/what-would-be-the-equivalent-this-for-loop-in-linq/18427840#18427840)'s answer.

However it's still creating a List in-between (`ForEach` comes only for `List<T>`). It's not very readable, better to use non-mutable approach and just generate new list basing on given criteria.