15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

502<br />

Branching Statements<br />

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

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, PHP also include combination assignment and mathematical operators,<br />

as shown in Table 4-4.<br />

Table 4-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 / 35)<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 runs only one or<br />

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

if (condition) {<br />

Command;<br />

}<br />

To make the computer choose between two mutually exclusive sets of commands,<br />

you can use an IF-ELSE statement, such as<br />

if (condition) {<br />

Command;<br />

}<br />

else {

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

Saved successfully!

Ooh no, something went wrong!