My Drive

05. Decisions 본문

programming

05. Decisions

sunnyeo.park 2014. 10. 25. 10:03

1. If (single-statement)

◦ example :

if(x.gt.0.) x=sqrt(x)


2. If (block)

◦ example :

if(x.gt.0.) then

x=sqrt(x)

y=y-x

endif


3. If-Then-Else ( end if == endif )

◦ example :

if(x.lt.0.) then

write(*,*) ’x is negative’

else

if(x.gt.0.) then

write(*,*) ’x is positive’

else

write(*,*) ’x must be zero’

endif

endif


4. If-Then-Elseif- ... - Else - Endif ( else if == elseif )

◦ example :

if(x.lt.0.) then

write(*,*) ’x is negative’

elseif(x.gt.0.) then

write(*,*) ’x is positive’

else

write(*,*) ’x must be zero’

endif


5. Case ( integer, logical, character )

◦ example :

read(*,*) i

select case(i)

case(1)

write(*,*) ’excellent’

case(2,3)

write(*,*) ’OK’

case(4:6)

write(*,*) ’shame on you’

case default

write(*,*) ’impossible’

end select





'programming' 카테고리의 다른 글

07. Arrays  (0) 2014.10.27
06. Input / Output  (0) 2014.10.27
04. Loops  (0) 2014.10.25
03. Expressions  (0) 2014.10.25
02. Data types (자료형)  (0) 2014.10.24
Comments