測試環境為 CentOS 8 x86_64 (虛擬機)
參考文章 – https://shengyu7697.github.io/python-while/
[root@localhost ~]# python3 Python 3.6.8 (default, Mar 25 2022, 11:15:52) [GCC 8.5.0 20210514 (Red Hat 8.5.0-10)] on linux Type "help", "copyright", "credits" or "license" for more information.
- 範例 : while
>>> i=0 >>> while (i<5): ... print(i) ... i+=1 ... 0 1 2 3 4
- 範例 : while else
>>> i=0 >>> while (i<5): ... print(i) ... i+=1 ... else: ... print("End Loop") ... 0 1 2 3 4 End Loop
- 範例 : while True
>>> i=0 >>> while True: ... print (i) ... i+=1 ... if i>5: ... break ... 0 1 2 3 4 5
沒有解決問題,試試搜尋本站其他內容