Relational & Logical Expression |
| |
Operator |
Meaning | |
.LT. Or < = |
Less Than | |
.LE. Or = = |
Less than or Equal to | |
.EQ. Or / = |
Equal to | |
.NE. or > = |
Not Equal to | |
.GT. Or < |
Greater Than | |
.GE. Or 2x |
Greater than or equal to | |
.AND. |
True if both A and B are true | |
.OR. |
True if either A, B, or both, are true | |
.NEQV. |
True if either A or B is true, but false if both are true | |
.XOR. |
Same as .NEQV. | |
.EQV. |
True if both A and B are true, or both are false | |
.NOT. |
True if A is false and false if A is true |
if(i-j) 10,20,30
일반적인 if문 즉 다른 언어와 좀 다른것을 알수가 있다.
위의 예에서 조건이 음수이면 문번호 10으로 이동,조건이 0이면 20,조건이 양수이면 30으로 이동된다.
if(a .eq. b) write(*,*) "="
조건이 참일때 즉, a와b의 값이 같을때 '='를 출력해준다.
포트란에만 있는 듯한 if문의 사용방법이었다.
일반적인 if문도 사용할수 있다.
if(condition-a) then
a true statement
else if(condition-b) then
b true statemant
else
statemant
endif
do
반복적으로 해당영역을 실행해야 할 경우에 사용
씨나 베이직에서도 do문은 있다. 그것과 유사하다.
do 문번호 변수=시작값,끝값
내용
문번호 continue
do 10 i=1,10
j=j+i
10 continue
write(*,*) j
stop
end
do문에서 지정된 문번호까지 시작값1에서 끝값10까지 i의 값이 1씩 증가하면서 반복해준다.
문번호 10번에는 continue문으로 해주어야 한다.왜냐? 문법이 그런것이다.
그렇지만 continue문 없이도 사용할수 있다.
do i=1,10
j=j+i
enddo
write(*,*) j
stop
end
이렇게 사용해도 된다.
파일에서 값을 읽어 들일때
real a(2,2), b(2,2), c(2,2)
open(9,file='test.in')
read(9,*) ((a(i,j),j=1,2),i=1,2)
다른 컴퓨터 언어에는 없는 사용법이다.
위의 내용은 아래의 내용과 같은 결과이다.
real a(2,2), b(2,2), c(2,2)
open(9,file='test.in')
do i=1,2
do j=1,2
read(9,*) a(i,j)
enddo
enddo
어떤 식으로 사용하든 편한데로 사용하면 된다.
그러나 포트란의 특징은 알고 있어야 할 것이다.