> For the complete documentation index, see [llms.txt](https://nmdkims-organization.gitbook.io/python-hand-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nmdkims-organization.gitbook.io/python-hand-book/day1./2.-if-else-for/while-for-loop.md).

# while, for loop 반복

{% hint style="info" %}
**while, for loop 반복문**

```
while 조건문:
```

```
    수행할 문장
```

{% endhint %}

```python
open = 0

while open < 10:
    open += 1
    print(f"{open}번 상자를 열었습니다.")
    if open == 10:
        print("모든 상자를 열었습니다.")

```

{% hint style="info" %}

```
위의 문장은 open이 10보다 작으면 계속 반복합니다.
```

```
아래 수행하는 문장을 보면 open에 값을 계속 1씩 증가시키고 
```

```
open 10이 되면 모든 상자를 열었다는 문장을 출력 후 open이 10이되어
```

```
open이 10보다 작다는 조건이 False가 되어 while문에서 빠져나옵니다.
```

{% endhint %}

{% hint style="info" %}

```
while문의 break continue
```

```
break: while문을 강제로 빠져나가고 싶을 때
```

```
continue: while문을 빠져 나가지 않고 맨 처음 조건문으로 돌아가고 싶을 때
```

{% endhint %}

```python
# break를 이용한 탈출
box = 10

while True:
    print("상자를 구매합니다")
    box -= 1
    if not box:
        print("상자가 0개라 더 이상 구매할 수 없습니다.")
        break

# continue를 이용한 홀수만 출력
num = 0

while num < 10:
    num += 1
    if num % 2 == 0:
        continue
    print(num)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nmdkims-organization.gitbook.io/python-hand-book/day1./2.-if-else-for/while-for-loop.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
