15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

490<br />

Branching Statements<br />

The decrement operator works the same way except that it subtracts 1 from<br />

a variable, such as<br />

j = 5;<br />

i = --j;<br />

In this example, the value of i is j - 1 or 4, and the value of j is also 4.<br />

If you place the decrement operator after the variable, such as<br />

j = 5;<br />

i = j--;<br />

Now the value of i is 5, but the value of j is 4.<br />

Assignment operators<br />

Most <strong>programming</strong> languages use the equal sign to assign values to variables,<br />

such as<br />

i = 59;<br />

However, JavaScript also includes combination assignment and mathematical<br />

operators, as shown in Table 3-4.<br />

Table 3-4<br />

Assignment Operators<br />

Assignment Operator Purpose Example<br />

+= Addition assignment i += 7 (equivalent to i = i + 7)<br />

-= Subtraction assignment i -= 4 (equivalent to i = i - 4)<br />

*= Multiplication assignment i *= y (equivalent to i = i * y)<br />

/= Division assignment i /= 3.5 (equivalent to i = i / 3.5)<br />

%= Modulo assignment i %= 2.8 (equivalent to i = i % 2.8)<br />

Branching Statements<br />

The simplest branching statement is an IF statement that only runs one or<br />

more commands if a Boolean condition is True, such as<br />

if (condition) {<br />

Command;<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!