First Spear Posted August 12, 2021 Share Posted August 12, 2021 Hi all. Just validating that this is the most performant way to do something if a number is odd: #chek = 1 IF #chek AND 1 then Print At 182 color 7 , "x" Thanks. Quote Link to comment Share on other sites More sharing options...
Kiwi Posted August 13, 2021 Share Posted August 13, 2021 (edited) MOD of 2, like 3%2 would be the remainder of 1. And 6%2 would be 0. i=variable%2 if i=1 then print at 182 color 7, "X" else print at 182 color 7, " " or if variable%2=1 then print at 182 color 7, "X" else print at 182 color 7, " " Edited August 13, 2021 by Kiwi Quote Link to comment Share on other sites More sharing options...
+nanochess Posted August 13, 2021 Share Posted August 13, 2021 "variable AND 1" or "variable % 2" are equivalent. And the fastest way with IntyBASIC. 3 Quote Link to comment Share on other sites More sharing options...
carlsson Posted August 13, 2021 Share Posted August 13, 2021 Also check the assembly code. Even if you don't understand much of the code, usually you can get an idea by counting how many instructions one line of BASIC generated. If it only yielded one or a few lines, you probably can assume it is the most efficient without completely rewriting your source code. 2 Quote Link to comment Share on other sites More sharing options...
Brian's Man Cave Posted August 15, 2021 Share Posted August 15, 2021 Basic question here... what does the % mean/do? Quote Link to comment Share on other sites More sharing options...
carlsson Posted August 15, 2021 Share Posted August 15, 2021 % is the modulo operator, i.e. it returns the remainder after a division: 5 / 2 = 2 with remainder 1 (2*2 + 1 = 5), so 5 % 2 = 1 9 / 3 = 3 with remainder 0 so 9 % 3 = 0 13 / 5 = 2 with remainder 3 so 13 % 5 = 3 In this case we want to check for odd or even numbers, i.e. if the remainder after dividing by 2 is 0 or 1. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.