Let me explain separately, since you are misssing the point.
The important point is NOT that there are duplicated points at (5,10). That is irrelevant. What matters is there is NOT a hold on, established after the first call to plot. So look at the flow:
- The point (5,10) is plotted.
- The point (5,4) is plotted, BUT as a new plot, because hold on was not employed. If you just call plot TWICE in a row, without a hold on in between the previous plot figure is deleted.
- The point (5,10) is plotted AGAIN. But again, the last plot gets zapped into the bit bucket.
- Finally, a point at (3,10) is plotted, but before this is done, hold is set to on. So now future points are plotted on the same set of axes. You need not set hold to on again for this set of axes. Hold stays on, until it is turned off, or until the figure is deleted.
- Since hold is now on, the remaining points are plotted. A total of 4 points are seen.
In fact, 6 points were plotted. But the first two points were lost in the bit bucket. It has nothing to do with the replicated point, but with the failure to issue a hold on immediately.
Your code never hits the call to hold UNTIL the 4th point was plotted on those axes, because the first three calls all had A(n)==5. In your code, hold is never set in the block where A(n)==5. Repeated calls to plot will delete the previous figure if hold is not set to on.