> For the complete documentation index, see [llms.txt](https://python.dainganxanh.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://python.dainganxanh.com/chuong2/bai-13.-lenh-break-va-continue.md).

# Bài 13. Lệnh break và continue

Lệnh break và continue dùng để xử lý trong trường hợp muốn thoát khỏi vòng lặp với một điều kiện ngoài điều kiện chung của vòng lặp bình thường.

Ví dụ sử dụng break:

```python
for val in "Học để biết":
    if val == "b":
        break
    print(val)
print("Kết thúc.")
input()
```

Output: Chương trình gặp chữ “b” sẽ thoát khỏi vòng lặp

`H`\
`ọ`\
`c`\
`đ`\
`ể`\
`Kết thúc.`

Ví dụ sử dụng continue:

```python
for val in "Học để biết":
    if val == " ":
        continue
    print(val)
print("Kết thúc.")
input()
```

Output: chương trình gặp khoảng trắng sẽ bỏ qua để thực thi tiếp vòng lặp

`H`\
`ọ`\
`c`\
`đ`\
`ể`\
`b`\
`i`\
`ế`\
`t`\
`Kết thúc.`

Ngoài ra còn có lệnh pass dùng để thoát khỏi một hàm hay vòng lặp (không thực thi hàm hay vòng lặp đó trong chương trình.

Ví dụ:

```python
for val in sequence:
    pass
# Hoặc
def function(args):
    pass
# Hoặc
class Example:
    pass
```


---

# 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, and the optional `goal` query parameter:

```
GET https://python.dainganxanh.com/chuong2/bai-13.-lenh-break-va-continue.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
