Programming Language Control Structures
프로그래밍에서 코드의 실행 흐름을 제어하는 핵심적인 구문이다.
Iteration Structures
특정 코드 블록을 반복적으로 실행하기 위한 구조
Language | For Loop | While Loop | Do-While | For-Each/Range |
---|---|---|---|---|
Python | for x in sequence | while condition | N/A | for x in iterable |
Java | for(init;condition;increment) | while(condition) | do {…} while(condition) | for(Type x: collection) |
JavaScript | for(let i=0;i<n;i++) | while(condition) | do {…} while(condition) | for(let x of iterable) |
TypeScript | Same as JavaScript + type safety | Same as JavaScript | Same as JavaScript | Same as JavaScript |
Golang | for i:=0; i<n; i++ | for condition | N/A | for _, v:= range slice |
Kotlin | for (i in range) | while(condition) | do {…} while(condition) | for (item in collection) |
Rust | for x in iter | while condition | loop {…} | for x in collection |
Conditional Statements
특정 조건에 따라 다른 코드 블록을 실행하도록 하는 구조
Language | If-Else | Switch/Match | Ternary | Pattern Matching |
---|---|---|---|---|
Python | if/elif/else | match (3.10+) | a if cond else b | Limited |
Java | if/else if/else | switch | cond? a: b | N/A |
JavaScript | if/else if/else | switch | cond? a: b | N/A |
TypeScript | Same as JavaScript | Same as JavaScript + type patterns | Same as JavaScript | N/A |
Golang | if/else if/else | switch | N/A | N/A |
Kotlin | if/else if/else | when | if(cond) a else b | when expressions |
Rust | if/else if/else | match | N/A | Full pattern matching |
Exception Handling
프로그램 실행 중 발생할 수 있는 오류 상황을 관리하는 메커니즘
Language | Try-Catch | Finally | Custom Exceptions | Error Types |
---|---|---|---|---|
Python | try/except | finally | Class inheritance | Exception hierarchy |
Java | try/catch | finally | Class inheritance | Checked/Unchecked |
JavaScript | try/catch | finally | Class inheritance | Error object |
TypeScript | Same as JavaScript | Same as JavaScript | Same as JavaScript + types | Same as JavaScript |
Golang | N/A (uses error returns) | defer | Custom error types | Error interface |
Kotlin | try/catch | finally | Class inheritance | Exception hierarchy |
Rust | Result<T,E> | N/A | Custom error types | Result/Option types |