Replacing the Zeros of One List by the (i-1)th Element of Another List

You can use a multiplication instead of looping or conditionals:

list1 + (1 - list1) Prepend[Most[list2], 0]

{0, 1, 1, 4, 7, 1, 1, 10, 1, 11, 3, 1, 0}

The central point is that 0 and 1 in list1 aren't just symbols but numeric quantities.


idx = Random`Private`PositionsOf[Rest[list1], 0];
result = list1;
result[[idx + 1]] = list2[[idx]];
result

{0, 1, 1, 4, 7, 1, 1, 10, 1, 11, 3, 1, 0}


Here's another possibility:

Module[{tmp=list1},
    With[{i = Pick[Range[Length[list1]-1], Rest @ list1, 0]},
        tmp[[i+1]]=list2[[i]]
    ];
    tmp
]

{0, 1, 1, 4, 7, 1, 1, 10, 1, 11, 3, 1, 0}