Forth (programming language): Difference between revisions

Content deleted Content added
Ternary operators are a class of operators. C only has one ternary operator, the conditional operator.
Line 83:
The subroutine uses the following commands: <code>DUP</code> duplicates the number on the stack; <code>6</code> pushes a 6 on top of the stack; <code>&lt;</code> compares the top two numbers on the stack (6 and the <code>DUP</code>ed input), and replaces them with a true-or-false value; <code>IF</code> takes a true-or-false value and chooses to execute commands immediately after it or to skip to the <code>ELSE</code>; <code>DROP</code> discards the value on the stack; <code>5</code> pushes a 5 on top of the stack; and <code>THEN</code> ends the conditional.
 
The <code>FLOOR5</code> word is equivalent to this function written in the [[C (programming language)|C programming language]] using the [[?:|ternaryconditional operator]] '?:'
<syntaxhighlight lang="c">
int floor5(int v) {