Jump to content
IGNORED

IntyBASIC Odd Number Check?


Recommended Posts

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 by Kiwi
Link to comment
Share on other sites

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.

  • Like 2
Link to comment
Share on other sites

% 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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...