Welcome to the forum!
Just to give you some background into why dan's method works and yours doesn't - remember that the PLC runs code one line at a time, and does exactly what each line says. At no point does the PLC encounter some code and say "yeah but something else turned this on before so that's OK". Once the PLC has run it's code all the way to the end, it will then turn on and off it's physical outputs according to the state of the outputs at the end of the scan.
(disclaimer: this is not a 100% hard and fast rule, there are other processors that operate differently, but for your purposes this is how you should look at and understand it)
So in your example, the following scenarios could occur:
- If I:1/2 AND I:1/4 are both ON, rung 000 says "turn on O:2/2". Then rung 001 says "turn on O:2/2". At the end of the scan, O2:2 is on, so the physical output gets turned on.
- If I:1/2 AND I:1/4 are both OFF, rung 000 says "turn off O:2/2". Then rung 001 says "turn off O:2/2". At the end of the scan, O2:2 is off, so the physical output gets turned off.
- If I:1/2 is OFF and I:1/4 is ON, rung 000 says "turn off O:2/2". Then rung 001 says "turn on O:2/2". At the end of the scan, O2:2 is on, so the physical output gets turned on.
You can see where this is going.
- If I:1/2 is ON and I:1/4 is OFF, rung 000 says "turn on O:2/2". Then rung 001 says "turn off O:2/2". At the end of the scan, O2:2 is of, so the physical output gets turned off.
If you did program like this in the real world, it's basically a case of "last rung wins". But it can cause a whole lot of problems if you have other logic in between those rungs examining the state of that output!
As dan says, as a general rule, you should only ever use a destructive instruction on a binary element once.
(destructive: an instruction that can change the state of the bit, like OTE, OTL, OTU, but not XIC, XIO)