Jump to content

I cannot understand these operators


Maisara-WD

Recommended Posts

Hi guyspeace upon ucan u explain those operations for me??% Modulus (division remainder)++ Increment-- Decrement thanks

Link to comment
Share on other sites

Guest FirefoxRocks
Hi guyspeace upon ucan u explain those operations for me??% Modulus (division remainder)++ Increment-- Decrement thanks
Increment - Adds 1If...
i = 3;i++;

then i would equal 4.Decrement - Subtracts 1

i = 3;i--;

i would equal 2.i++ is the same as i = i+1;i-- is the same as i = i-1;

Link to comment
Share on other sites

% Any division operation can also be thought of as a fraction. Assuming integers for both the numerator and denominator, if you completely reduce the fraction (extracting the largest whole number value possible) there will or won't be a fractional portion less than zero that is "left over." If nothing is left over, % returns 0 or false. If a fractional part remains, % returns the numerator. This is especially useful in loops where you want to test if the iterating variable is a whole-number multiple or denominator of some value.Example: for i = 1 to 100. i % 10 returns false if i equals 10, 20, 30 etc.Example: for i = 1 to 100. i % 2 returns false if i is an even number, true if it's an odd numberFirefoxRocks has you covered on the others.

Link to comment
Share on other sites

Example: for i = 1 to 100. i % 10 returns false if i equals 10, 20, 30 etc.Example: for i = 1 to 100. i % 2 returns false if i is an even number, true if it's an odd number
Maisara, keep in mind that 0 is evaluated as false and non-0 is evaluated as true.39 / 10 = 3 + (9 / 10)39 % 10 = 9
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...