Here’s what the theory actually says: if you know the number of iterations exactly, it’s a Nash equilibrium for both to defect on all iterations. But if you know the chance that this iteration will be the last, and this chance isn’t too high (e.g. below 1⁄3, can’t be bothered to give an exact value right now), it’s a Nash equilibrium for both to cooperate as long as the opponent has cooperated on previous iterations.
Here’s what the theory actually says: if you know the number of iterations exactly, it’s a Nash equilibrium for both to defect on all iterations. But if you know the chance that this iteration will be the last, and this chance isn’t too high (e.g. below 1⁄3, can’t be bothered to give an exact value right now), it’s a Nash equilibrium for both to cooperate as long as the opponent has cooperated on previous iterations.