Upcoming SlideShare
×

# 9 case

148
-1

Published on

Published in: Education
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
148
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
2
0
Likes
0
Embeds 0
No embeds

No notes for slide

### 9 case

1. 1. Basic Scientific Programming Case Statement
2. 2. The Case Construct  Used in cases where exactly one of several alternative actions is selected and performed. form Select Case(Selector) case(label-list1) statement sequence1 case(label-list2) statement sequence2 “ case(label-list n) statement sequence n End select
3. 3.   Selector is an integer, character, or logical expression. The values in the list may have any of the forms: (value) single value (value1: value2) range of values from value1 through value2. (value1:) range of values greater than or equal to value1 (: value2) range of values less than or equal to value2
4. 4. Example  Select Case(Class_Code) Case(1) print*,’Freshman’ Case(2) print*,’Sophomore’ Case(3) print*,’Junior’ Case(4) print*,’Senior’ Case Default print*, ‚error,Illegal code‛ End Select
5. 5. Example: Pollution Index   A case statement can be used to carry out the classification given (good, fair, or poor). A case statement can be used to replace an IF / ELSE IF structure.
6. 6. Range Selectors “Integers”  Select Case(Int(average)) case(90:) grade = ‚A‛ case(80:89) grade = ‚B‛ case(70:79) grade = ‚C‛ case(60:69) grade = ‚D‛ case(:59) grade = ‚F‛ End Select
7. 7. Range Selectors “Characters”  Select Case(char) case(‘A’: ‘Z’) Print*, ‘uppercase’ case(‘a’: ’z’) Print*, ‘lowercase’ case(‘0’:’9’) Print*, ‘numbers’ case default Print*, ‘Not a letter or number’ End Select
8. 8. What about real valued selectors??   A selector can’t be of type real. To make a selection, convert the real number to an integer and then use it for the selection.
9. 9. example Suppose a motors’ RPM is determined by an indicator x.  high speed x>= 5.5  normal speed 2.5<= x < 5.5  Low speed x < 2.5 Select Case(int(10*x)) case(55:) print*, ‚HIGH SPEED‛ case(25:54) print*, ‚NORMAL SPEED‛ case(:24) print*, ‚LOW SPEED‛ End Select
1. #### A particular slide catching your eye?

Clipping is a handy way to collect important slides you want to go back to later.