If (logical)

Statement Type:

The simple logical if is an executable statement. It is Fortran's oldest decision making tool. Despite its age, the simple logical if can still be very useful.

Statement Purpose:

The logical if provides a simple decision making construct. It will execute a single statement as long as the expression provided to it evaluates to true.

Additional Required Statements:

if ( logical expression ) executable statement

With a simple logical if, you must provide it a logical expression to evaluate. If the expression is false, the program will go to the next line of code. If the expression evaluates as true, the executable statement that follows the logical expression will be performed.

Examples:

The following is what a Logical IF looks like. Remember that the print statement that follows the logical expression will only be executed by the computer if ldata is greater than or equal to 100.
		if (ldata.ge.100) print *,'There are to many data', 
	    & ' points'

Related Topics and Lectures:

lecture eleven

arithmetic if

block if

Up one level / Home


Written by Jason Wehr : jcw142@psu.edu and Maintained by John Mahaffy : jhm@cac.psu.edu