The Department of Computer Science & Engineering
cse@buffalo
STUART C. SHAPIRO: CSE 115 C

CSE 115
Introduction To Computer Science for Majors I
Lecture C
Lecture Notes #23
Stuart C. Shapiro
Spring, 2007


Selection and Loop Statements

Selection

One branch

if (condition) block
See primitivedemo.BoardFrame()

Two branch

if (condition) block
else block

See primitivedemo.IntFunction.solicitIntInRange(int i, int j)

Multi branch

if (condition) block
else if (condition) block
...
else block

while loops

while (condition) block

do block while (condition);
Equivalent to
block
while (condition) block

for loops

for (initialization; condition; increment) block
Equivalent to

{initialization;
 while (condition) {
    block
    increment}}
Note: The scope of variables declared in the initialization part is the entire for statement, including the block.

First Previous Next

Copyright © 2007 by Stuart C. Shapiro. All rights reserved.

Last modified: Fri Nov 16 09:50:02 EST 2007
Stuart C. Shapiro <shapiro@cse.buffalo.edu>