Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Programming in C Chapter 3 2004 년 가을학기 부산대학교 전자전기정보컴퓨터공학부.

Similar presentations


Presentation on theme: "Computer Programming in C Chapter 3 2004 년 가을학기 부산대학교 전자전기정보컴퓨터공학부."— Presentation transcript:

1 Computer Programming in C Chapter 3 2004 년 가을학기 부산대학교 전자전기정보컴퓨터공학부

2 Computer Programming Chapter 22 3 장. Control Flow 목차  Statement 와 Block  If-Else  Switch  Iteration : While  Programming Assignment #4  Iteration : Do-While  Iteration : For  Break and Continue  Programming Assignment #5

3 Computer Programming Chapter 23 1. Statement 와 Block Statement 프로그램의 최소단위 주로 semicolon(;) 으로 종료 Block 여러 개의 Statement 집합 {... } 로 범위 지정 프로그램의 단위 선언된 변수의 범위 (Scope) 를 지정

4 Computer Programming Chapter 24 2. If-Else if-else 기본적인 수행 순서 (control flow) 를 결정하는 방법 Syntax if( conditional_expression ) statement 1 (or block) else statement 2 (or block) if( condition ) statement if( condition 1 ) statement 1 else if ( condition 2 ) statement 2 else statement 3

5 Computer Programming Chapter 25 3. Switch 여러 개의 조건 문을 동시에 검사 Syntax switch(expression) { case value 1 : statement 1 case value 2 : statement 2... default : statement k } break 의 활용 value 1 value 2 Statement 1 Statement 2 Statement k...

6 Computer Programming Chapter 26 Iteration 반복적인 수행 예. 최소값, 최대값의 탐색 : 각 값을 반복적으로 비교 While Syntax while ( cond ) statement ( 또는 block) cond 이 만족될 경우 statement 를 계속 수행 4. Iteration - while 예. int sum=0; int i=1; while( i<=100) { sum=sum+i; i++; }

7 Computer Programming Chapter 27 6. Iteration – Do-while While 과 비슷한 효과 Syntax do statement (or block) while(condition ); 조건을 나중에 비교 : 적어도 한번은 statement 를 실행 예. int sum=0; int i=1; do { sum=sum+i; i++; } while (i<=100);

8 Computer Programming Chapter 28 7. Iteration – For While 과 비슷한 효과 Syntax for (initial_condition;termination_condition;increment) statement (or block) 초기조건, 각 반복 시 증가를 한꺼번에 표시 예. int sum=0; int i; for(i=1;i<=100;i++) sum=sum+i;

9 Computer Programming Chapter 29 8. Break and Continue Break Iteration block 에서 완전히 빠져 나오게 하는 statement Switch block 에서 빠져 나오게 하는 statement Continue Iteration block 의 수행을 한 번만 건너 뛰는 statement


Download ppt "Computer Programming in C Chapter 3 2004 년 가을학기 부산대학교 전자전기정보컴퓨터공학부."

Similar presentations


Ads by Google