Logical

Statement Purpose

The LOGICAL statement is used to declare variables and functions of type logical for use in the program.

Rules and examples of use

The logical type declaration statement is used in a similar manner to other type declaration statements. For instance, this type statement will support all of the attributes that the INTEGER and REAL statements support. Also, variables can be initialized inside of the type statement just like other type declaration statements. The only major difference between the logical type and other types is the fact that logical variables can only be assigned one of two values, .true. and .false. With this in mind, a logical type declaration statement will take on a form similar to the following when used.
		Logical, parameter :: lvar = .true.
or
		Logical, target,dimension(:,:) :: larray
The major use of these variables is to make logical comparisons within a program. The results of these comparisons could then be used as a condition for branching within a program. For instance, the next little block of code shows how a logical variable might be used with an if statement to cause branching within a program.
		if (lvar) then
			X = 5.6
			go to 1200
		else
			x = 76.8
			go to 1201
		end if

For more information and examples see

lecture ten

examples: iftests.f and inter1.f

Up one level / Home


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