The decrement and skip if less than command -- DS<( -- is a specialized conditional command. It is equivalent to an If conditional, except the next command will be skipped when the condition is true and it has a variable update built-in. However, it is not used very often (if anything, it is often misused as a looping command) because of its obscure name and somewhat limited application.
The DS<( command takes two arguments:
- A variable, which is limited only to one of the real variables (A-Z or θ).
- A value, which can be either a number, variable, or expression (a combination of numbers and variables).
When DS<( is executed it subtracts one from the variable (decrements it by one), and compares it to the value. The next command will be skipped if the variable is less than the value, while the next command will be executed if the variable is greater than or equal to the value.
The command DS<(A,B is equivalent to the following code:
:A-1→A :If A≥B
Here are the two main cases where the DS<( command is used:
:5→A :DS<(A,6 :Disp "Skipped
- Initializes the A variable to 5 and then compares to the value
- 5<6 is true so the display message won't be displayed
:3→B :DS<(B,2 :Disp "Not Skipped
- Initializes the B variable to 3 and then compares to the value
- 3<2 is false so the display message will be displayed
Note: In addition to both of these cases, there is also the case where the variable and the value are equal to each other. This case is shown below under the 'Advanced Uses' section because it has some added background that goes with it.
When you want the skipping feature of the DS<( command to always occur, you just have to use the same variable for both the variable and value arguments of the command:
An undefined error will occur if the variable and/or value doesn't exist before the DS<( command is used, which happens when the DelVar command is used. Consequently, you should not use DelVar with DS<(.
A similar code can be used as a substitute for B-1→B if you don't want to change Ans:
Note that due to the colon after the line, there will be no statement skipped, so you don't have to worry about that.
Because the DS<( command has the variable update built-in, it is smaller than manually incrementing a variable by one along with using an If conditional.
:A-1→A can be :DS<(A,0
The one caution about this is that if the variable is less than the value (in this case, '0'), the next command will be skipped. If you don't want the skipping functionality, then you need to make sure that the value is never greater than the variable. This is not always possible to do. Also, DS<( is slower than its more normal counterpart.
Related to the example code given, DS<( should always have a command following after it (i.e. it's not the last command in a program) because it will return an error otherwise. If you have no particular code choice, just put an empty string or something meaningless.
Using DS<( to decrement a variable is approximately 25% slower than using code like X-1→X. However, it is faster to use DS<( than to construct an If statement to do the same thing.
Note, however, that a quirk in the For( command (see its Optimizations section) will slow down the DS<( command significantly if a closing parenthesis is not used for the For( statement.
- ERR:INVALID occurs if this statement is used outside a program.
- ERR:SYNTAX is thrown if there is no next line to skip, or if there is only one next line and it is empty.
- ERR:UNDEFINED is thrown if the variable to be decremented is not defined.