Statement - Level Control Structures
Chapter 8. Statement - Level Control Structures
(Selection Statements , Iterative Statements 까지 일 듯)
Levels of control Flow
- Within expressions(ch.7)
--> operator associativity and precedence level
- Among program units(ch.9)
--> subprograms
- Among program statements (this chapter)
Contol Statements
Imperative language
- 명령형 언어에서의 computation : expression을 평가하고 resulting value를 variable에 assigning
- 이 computation을 더 flexible하고 powerful 하게 만들기 위한 추가적인 machanisms 존재
--> Selecting among alternative control flow path. ex) if, switch
--> Causing the repeated execution. ex) while, for
- 이같은 기능을 제공하는 statement를 control statements라고 한다.
Functional language
- 함수형 언어에서의 computation : expression을 평가하고 주어진 parameter를 function에 applying
- expression과 function의 flow는 다른 expression과 function에 의해 제어됨
Control Structure
- control statement와 이것이 실행을 제어하는 statement들의 collection
- Design question
--> Should a control structure have multiple entries?
Select Statements
- choosing between two or more paths of execution
--> Two - way selectors
--> Multiple - way selectors
Two-Way Selection Statements
- Design Issues:
--> What is the form and type of the control expression?
--> How are the then and else clauses specified?
--> How should the meaning of nested selectors be specified?
The Control Expression
- then 이 사용되지 않으면, () 를 씀
- C89, C99, Python, C++
--> control expression 에 arithmetic 사용 가능. ex> if((x+y) > 15)
Clause Form
- single statements or compound statements
- In Perl
--> 모든 clause를 다 { } 로 구분 (statement가 하나만 있어도 compound로 취급)
- 대부분 언어들이 복합문을 { }로 구분
- Python, Ruby : 복합문이라기보다 그냥 statement sequences
--> then 대신 : (colon) 사용
--> indentation으로 compound 표현
Nesting Selectors
- In Java
--> Java's static semantics rule : else는 nearest previous 한 if랑 match 됨
--> 이렇게 해야 if(sum == 0)과 else가 match됨
- In Ruby (statemetn sequences as clasuses)
- python 은 indentation으로 구분 // 쓰기 귀찮음 니가 아는 그거 맞음
Selector Expressions
- ML, F#, Lisp 에서 selector는 statement가 아닌, 값을 반환하는 expression임
--> if 식이 값을 반환하려면, else절을 반드시 가져야함
--> else절에 반환할 값이 없으면, unit type 이용(no value 라는 뜻)
--> then과 else절의 return value type 은 반드시 같아야함
to be continued...