반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- Kotlin
- google apps script
- numpy
- Tkinter
- Apache
- matplotlib
- PostgreSQL
- gas
- Google Spreadsheet
- PANDAS
- Redshift
- django
- c#
- Java
- dataframe
- hive
- string
- array
- SQL
- Python
- GIT
- Github
- PySpark
- Google Excel
- Excel
- list
- math
- 파이썬
- Presto
Archives
- Today
- Total
달나라 노트
C++ : while loop (반복문) 본문
728x90
반응형
while loop는 아래와 같이 사용할 수 있습니다.
while (condition) {
실행할 코드
}
while loop는 condition이 true인 경우에 코드를 실행합니다.
conditoin이 false가 되면 while loop를 빠져나옵니다.
#include <iostream>
using namespace std;
int main() {
int i = 1;
while (i <= 5) {
cout << i << '\n';
i = i + 1;
}
return 0;
}
-- Result
1
2
3
4
5
보면 i가 1씩 증가하다가 i=6이 되는 순간 i <= 5를 만족하지 못하게되고 while loop가 종료됩니다.
이는 while loop안에 있는 i = i + 1 이 부분에 의해 while loop가 한번 돌때마다 i가 1씩 증가하게 해뒀기 때문입니다.
만약 i = i + 1 부분이 없으면 while loop는 무한하게 돌게됩니다.
728x90
반응형
'C++' 카테고리의 다른 글
| C++ : 함수 (function, function overloading) (0) | 2022.03.23 |
|---|---|
| C++ : break, continue (0) | 2022.03.23 |
| C++ : for loop (반복문) (0) | 2022.03.23 |
| C++ : &&, ||, ! (논리 연산자, and, or, not) (0) | 2022.03.23 |
| C++ : switch ~ case (조건문) (0) | 2022.03.23 |
Comments