30.06.2013 Views

X - AS Nida

X - AS Nida

X - AS Nida

SHOW MORE
SHOW LESS

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

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

Assignment Operators<br />

Assignment Operators<br />

Assignment Operators<br />

Assignment Operators<br />

The right hand side of an assignment operator can be<br />

a complex expression<br />

There are many assignment operators, including the<br />

following:<br />

The entire right-hand expression is evaluated first,<br />

then the result is combined with the original variable<br />

Equivalent To<br />

Example<br />

Operator<br />

Therefore<br />

result /= (total-MIN) % num;<br />

is equivalent to<br />

x = x + y<br />

x = x - y<br />

x = x * y<br />

x = x / y<br />

x = x % y<br />

x += y<br />

x -= y<br />

x *= y<br />

x /= y<br />

x %= y<br />

+=<br />

-=<br />

*=<br />

/=<br />

%=<br />

result = result / ((total-MIN) % num);<br />

34<br />

33<br />

The for Statement<br />

The for Statement<br />

Repetition Statements<br />

Repetition Statements<br />

The for statement has the following syntax:<br />

Repetition statements allow us to execute a<br />

statement multiple times<br />

executed until the<br />

condition<br />

becomes false<br />

executed once<br />

before the<br />

loop begins<br />

Often they are referred to as loops<br />

Java has three kinds of repetition statements:<br />

for ( initialization ; condition ; update )<br />

statement;<br />

• the for loop<br />

• the while loop<br />

• the do loop<br />

Each kind of loop works slightly differently<br />

executed at the end<br />

of each iteration<br />

The condition-statement-update cycle is executed repeatedly<br />

36<br />

35

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

Saved successfully!

Ooh no, something went wrong!