5.语句控制结构

分支语句

单分支if 语句

  • 语法
    if condition :
    statement
    注意:冒号不能掉

双分支if 语句

  • 语法
    if condition :
    statement1
    else :
    statement2

多分支if语句

  • 语法
    if condition1:
    statement1
    elif condition2:
    statement2
    elif condition3:
    statement3
    ...
    else
    statementend

if嵌套(略)

循环语句

while循环

  • 语法
    while conditon :
    statement

while嵌套(略)

for循环与continue和break关键字

  • 语法
    for tempVariable in object
    statement
    吐槽:感觉像是pl/sql中的迭代循环,快速访问select的结果集用的东西
for i in range(1,6)
     print(i)

注:range()函数的使用,break结束整个循环,continue结束本次循环

posted @ 2025-06-04 19:51  噫~该死的碳酸饮料  阅读(15)  评论(0)    收藏  举报