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.

548<br />

Branching Statements<br />

Table 2-7 (continued)<br />

Assignment Operator Purpose Example<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 only runs 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 {<br />

Command;<br />

}<br />

Java and C# also offer an IF-ELSEIF statement, which uses two or more<br />

Boolean conditions to choose which of two or more groups of commands to<br />

run, such as<br />

if (condition1) {<br />

Command;<br />

}<br />

else if (condition2) {<br />

Command;<br />

}<br />

Although the IF-ELSE statement can only give the computer a choice of two<br />

groups of commands to run, the IF-ELSEIF statement can offer the computer<br />

multiple groups of commands to run, such as

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

Saved successfully!

Ooh no, something went wrong!