Laurent, I initially got the same result as you. After the OP declared that wrong, I went back to his code. The difference is that he only updates the history if he does the print. I now believe that is intentional. That would be correct, but he now has an additional requirement which looks like a mere comment.

Quote

But because the x=8 is printed out, x=7 will be printed out as well

After line 8 is processed, but before it is printed, he has to print line 7 and revise the history so that line 9 will get its pre from line 8 and its pre_pre from line 7 (not 2).

I assume that this processing is needed every time a line is printed, and its immediate successor was not. It would not make sense to consider this requirement recursive.

Yes, Bill, yes, of course, you are right, I fully understand that what I provided is not what the OP really wanted. But it is my best understanding of the way the OP described the problem. And the code provided does in my opinion what the OP requested.

From the OP's own recognition, his or her code does not do what he or she wants. Therefore, you or I can't rely on the code provided by the OP to guess what he or she wants.

The reason I challenged the OP's opinion that my solution was wrong is certainly not that I wanted absolutely to defend my code (I frankly don't care), the OP hopefully knows better that you or I what he or she wants. The reason I did it is simply to prompt the OP to give better specifications of the requirement.

The table provided by the OP is only confusing to my eyes: for every single line, the second member of the equation if "-0.4 * 2". Even though I have an idea why, the point is that an example is never a substitute for a real explanation of the rule.

I have an idea of what the OP really wants, but I want him or her to state it clearly and to explain precisely the rules of the game.

It is probably not very complicated to obtain the desired result, but I will not commit any more effort on this until the need is clearly specified. Once we know really what the OP wants, I'm willing to take it up again.

To the OP: don't take this as an attack, it is not that, I am just trying to say that you need to make clear what you really want. Quite possibly, if you do the exercise seriously, you will find the solution by yourself. Believe my long experience: dfefining clearly what you need is the key to success. The programming itself is a secondary matter. I have been using probably more than 20 programming languages in my life, of which at least a dozen for real life professional problems, the issue of figuring out exactly what you need is far more important that knowing whether it will be programmed in Fortran, Lisp, C, PHP or Perl (or whatever).

The table provided by the OP is certainly confusing. But, once I deciphered it, I considered it a reasonably complete description of the problem. My previous post was not based on any guess. It is fully consistent with my understanding of the table. I had hoped that with that much clarification, we could both work on the real problem.

Please reconsider your response. Look at the table once more with the idea that it does contain the spec that you want. The first six lines are consistent with the OP's code. The seventh is different because of an additional requirement explained in the comment.

Note: Pre and Pre_Pre do not refer the previous physical lines, but to the two previously printed lines.

x and y refer to the integer and real parts of a line respectively

You complained about all the 0.4's in the PRE colulmn. In rows 3 through 8, the 0.4 is the y-value from row 2 (the previously printed row.) The OP documents this with the notation '(y of 2)' Row 8 is printed. The 0.4 in rows 9 and 10 is the y-value from row 8 which has become the previous printed row. It is an unfortunate coincidence that those y-values are the same.

The PrePre column is more complicated. Rows 2 through 8 contain the y-value from row 1 (the second previously printed row.) Without the new requirement to print row 7, rows 9 and 10 would both use the y-value from row 2. Now that row 7 is printed, they must get the y-value from it. Good Luck, Bill

I still think that the OP should learn to express requirements more precisely in plain language, but I can't resist to the pleasure of problem solving.

This is my new version. I am not entirely sure how exactly $pre_value and $pre-pre_value should be modified when one line is printed because the next one matches the condition, I have implemented what looks the most plausible to me.

Thanks Laurent, that is exactly what I wanted. I hope the OP can say the same thing.

I found your solution this morning before I had a chance to work on it more myself. Everything I had considered so far was much more complex. I had not thought of extracting the special previous value from the previous line. Good Luck, Bill