Thursday, May 28, 2009

Java tutorial Decision Control Structures: if statement

Decision control structures are Java statements that allows us to select and execute specific blocks of code while skipping other sections.

if statement

The if-statement specifies that a statement (or block of code) will be executed if and only if a certain boolean statement is true.

The if-statement has the form,

if( boolean_expression )
statement;

or

if( boolean_expression ){
statement1;
statement2;
. . .
}

where, boolean_expression is either a boolean expression or boolean variable.

For example, given the code snippet,

int grade = 68;

if( grade > 60 ) System.out.println("Congratulations!");

or

int grade = 68;

if( grade > 60 ){
System.out.println("Congratulations!");
System.out.println("You passed!");
}

Related Post:

PHP Tutorial

Java programing source code sample printing characters

What is programming?

C programming sample source code: Sum of 2 numbers

Java Programming Features