Basic HTML version of Foils prepared Feb 19 1999

Foil 15 "if" statements

From Computing and Java Language Basics NPAC Java Academy February--April 99 -- Feb 13 1999. by Nancy McCracken


This statement is also called a "conditional" statement. It tests a "condition" and if it's true, it executes the first set of statements, and if it's false, instead it executes a second set of statements.
if ( num == 0 )
{ y = 0; g.setColor ( Color.red ); }
else
{ y = 1; g.setColor ( Color.black ); }
if and else are keywords
The condition is in ( )s.
If the condition is true, execute these statements,
otherwise these.



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Mon Jul 5 1999