1. 程式人生 > 其它 >boot入門思想 spring_SpringBoot入門建站全系列(二十)SpringDataJpa使用樂觀鎖與悲觀鎖...

boot入門思想 spring_SpringBoot入門建站全系列(二十)SpringDataJpa使用樂觀鎖與悲觀鎖...

技術標籤:python基礎知識點手冊python

while 迴圈

while 語句用於在表示式保持為真的情況下重複地執行。語法如下:

while assignment_expression:
    suite
else: # 可選子句
    suite

對於簡單語句可以寫為一行,但不推薦。

這將重複地檢驗表示式,如果其值為真就執行其下的程式碼;表示式值為假則如果 else 子句存在就會被執行並終止迴圈。

i = 0
while i < 3: print(i); i += 1
0
1
2
i = 0
while i < 3: 
    print(i)
    i +=
1 else: # i 為 3 時執行 print(f'i={i}') print('end')
0
1
2
i=3
end