Message 1 of 7
Toggle a variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here's a little lsp routine that I started using many years ago when I needed to toggle a variable (one that is either 0 or 1).
(setq v (- 1 v))
If the variable starts out as 1, then subtract 1 from 1 and get 0. If the variable starts out as 0, then subtract 0 from 1 and get 1.
I just thought someone might find it useful. It works better than using an if statement.
Command: (setq v 1) 1 Command: (setq v (- 1 v)) 0 Command: (setq v (- 1 v)) 1 Command: (setq v (- 1 v)) 0
Don Ireland
Engineering Design Technician
If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.
Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.