Hi,
I'm somewhat new to Forth. The documentation says that a DUP before an IF would be optimized but I don't understand a situation where a DUP before an IF would be useful. Could you help me with some examples?
The only situation where I'd use DUP before an IF would be to check for zero/non-zero, but this is already handled with the 0= condition.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You would use DUP if you need a copy of the test value for other use later in the code.
The optimization makes the test non-destructive of the top of stack.
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm somewhat new to Forth. The documentation says that a DUP before an IF would be optimized but I don't understand a situation where a DUP before an IF would be useful. Could you help me with some examples?
The only situation where I'd use DUP before an IF would be to check for zero/non-zero, but this is already handled with the 0= condition.
You would use DUP if you need a copy of the test value for other use later in the code.
The optimization makes the test non-destructive of the top of stack.