# 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: 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://python.dainganxanh.com/chuong2/bai-13.-lenh-break-va-continue.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.
