05-18 01:37
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Unity
- Polymolphism
- Physical Scheme
- Entity
- dbms
- descriptive statistics
- Class
- X.org
- Reference Type
- BFS
- python
- External Scheme
- systemd
- spring
- X윈도우
- preprocessing
- literal
- 셀레니움
- Operator
- OOP
- 자바
- Binary Search
- Entity Set
- Mac
- Java
- Inheritance
- 리눅스
- selenium
- 백준
- 리눅스 마스터 1급
Archives
- Today
- Total
Byeol Lo
Computer Language - Condition & Loop 본문
보통 프로그램들은 일련의 순서로 처리가 된다. 이를 Sequential flow라고 하는데, 우리는 어떤 조건에 따라 이 순차 처리를 경우를 나눠 처리하고 싶을 때가 있다.
Condition 조건문
보통 Relational Operators(==, <=, !=, >=, <, >), Conditional Operators(||, &&, !) 등을 사용해서 조건문 표현을 하게된다.
- IF Statements : 다양한 변수에 대한 조건을 처리하고 싶을때 사용
- Switch Statements : 하나의 변수에 대한 다양한 값에 따라 조건을 달리 하고 싶을때 사용
if((n = 2) == 3) { // 값 할당과 동시에 조건문 비교
System.out.println("hihi");
}
int n = 10;
switch(n) {
case 1:
System.out.println("hi");
break;
case 5:
System.out.println("hihihihihi");
break;
case 10:
System.out.println("hihihihihihihihihihihi");
break;
default :
System.out.println("--");
}
Ternary Statement
int x = (2>1) ? 2:1; //2가 저장됨
Loop 반복문
- for statement : 다양한 변수(혹은 코드)를 초기화(한번 실행)하고, 조건에 맞으면 코드 블록을 실행, 다 실행 후 표현식을 수행하고 다시 조건에 맞는지 수행 후 코드 블록을 실행.
- while statement : 조건이 거짓일 때까지 반복
- do-while statement : 한번은 무조건 실행한 후에 조건이 거짓일 때까지 반복
// for(initialization; condition; expression)
for(int i=0; i<10; i++) {
System.out.println(i);
}
for(i=0;;) { //true 생략가능
System.out.println("무한루프");
}
for(i=0;;i++, System.out.println(i)){
}
int sum;
for(i=0, sum=0; i<=100; i++) {
sum += i;
}
System.out.println(sum);
// while(condition)
int i=0;
while(i<10) {
i++;
}
// do - while
do {
System.out.println(i);
i++;
} while (i<10);
'Programming Language > Java' 카테고리의 다른 글
Computer Language - OOP (1) (0) | 2023.05.01 |
---|---|
Computer Language - Reference Type (0) | 2023.05.01 |
Computer Language - Basic Operators (2) | 2023.03.22 |
Computer Language - I/O System (0) | 2023.03.22 |
Computer Language - Casting(Type conversion) (0) | 2023.03.13 |
Comments