# 10.流程控制

### 1. 条件语句 if/else

```python
if condition:
    #####
elif condition:
    #####
else: 
    ##### 
```

在 Python 中，没有 switch/case 语句\
​

### 2. 循环语句 while/for

```python
# while 语句

while condition:
    #### condition 满足执行
else:
    #### 循环结束执行
    
      
# for 语句

for <variable> in <sequence>:
    #### 
else:
    #### 循环结束执行

```

### 3. Range函数

**Python** 内置 range 函数可以创建一组数列(不是list)\
​

```python
range1 = range(5)           # 0,1,2,3,4

range2 = range(1,5)         # 1,2,3,4

range3 = range(1,10,2)      # 1,3,5,7,9         2 为 步长


li = list(range(1,11))      # 使用range创建 list
```

​

### 4. break/continue

break 语句用于跳出循环体\
​

continue 语句用于结束当前这次循环，继续下一次循环\
​

跳出循环体之后，else 语句将不会执行

### 5. pass

Python 的 **pass** 是空语句，是为了保持程序结构的完整性。**pass**​ 不做任何事情，一般用做占位语句

```python
for letter in 'Runoob': 
   if letter == 'o':
      pass
      print ('执行 pass 块')
   print ('当前字母 :', letter)
 
print ("Good bye!")


'''
当前字母 : R
当前字母 : u
当前字母 : n
执行 pass 块
当前字母 : o
执行 pass 块
当前字母 : o
当前字母 : b
Good bye!
'''
```


---

# 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://gitbook.existorlive.cn/kai-fa-yu-yan-xue-xi/python/10.-liu-cheng-kong-zhi.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.
