Java Programming/Keywords/if

From Wikibooks, open books for an open world
< Java Programming‎ | Keywords
Jump to: navigation, search

if is a Java keyword. It starts a branching statement.

The general syntax of a if, using Extended Backus-Naur Form, is

branching-statement ::= if condition-clause 
                                    single-statement | block-statement
                       [ else 
                                    single-statement | block-statement ]
 
condition-clause    ::= ( Boolean Expression )
single-statement    ::= Statement
block-statement     ::= { Statement [ Statements ] }

For example:

Computer code
if ( boolean Expression )
{
   System.out.println("'True' statement block");
}
else
{
   System.out.println("'False' statement block");
}

See also: