---
title: 循环
date: 2024-06-06T23:51:38Z
tags: []
---

## if

```python
if 条件:
    #程序
elif 条件:
    程序
else:
    程序
```

## for

```python
for 变量 in 可迭代对象:
    循环体代码
```

### for..else(for 正常循环完后才会运行)

```python
for 变量 in 可迭代对象:
    循环体代码
else :
    语句块
```

## while

```python
while 条件:
    循环体代码
```

## 模式匹配(3.11 后)

```python
match x:
    case 0:
        print("x is zero")
    case 1 | 2:
        print("x is one or two")
    case _:
        print("x is some other value")

```
