- Learning Python for Forensics
- Preston Miller Chapin Bryce
- 261字
- 2021-08-20 10:17:04
The while loop
while loops are not encountered as frequently in Python. A while loop executes as long as a statement is true. The simplest while loop would be a while True statement. This kind of loop would execute forever since the Boolean object True is always True and so the indented code would continually execute.
If you are not careful, you can inadvertently create an infinite loop, which will wreak havoc on your script's intended functionality. It is imperative to utilize conditionals to cover all your bases such as if, elif, and else statements. If you fail to do so, your script can enter an unaccounted situation and crash. This is not to say that while loops are not worth using. while loops are quite powerful and have their own place in Python:
>>> guess = 0
>>> answer = 42
>>> while True:
... if guess == answer:
... print('You've found the answer to this loop: ' + str(answer))
... break
... else:
... print(guess, 'is not the answer.')
... guess += 1
The break, continue, and pass statements are used in conjunction with for and while loops to create more dynamic loops. The break escapes from the current loop, while the continue statement causes the PVM to begin executing code at the beginning of the loop, skipping any indented code following the continue statement. The pass statement literally does nothing and acts as a placeholder. If you're feeling brave or bored, or worse, both, remove the break statement from the previous example and note what happens.
- CTF實戰(zhàn):技術(shù)、解題與進(jìn)階
- 諸神之眼:Nmap網(wǎng)絡(luò)安全審計技術(shù)揭秘
- Applied Network Security
- 網(wǎng)絡(luò)運維親歷記 (網(wǎng)絡(luò)運維紀(jì)實文學(xué))
- 軟件安全保障體系架構(gòu)
- Advanced Penetration Testing for Highly:Secured Environments(Second Edition)
- 信息安全導(dǎo)論(第2版)
- Web安全之深度學(xué)習(xí)實戰(zhàn)
- 數(shù)據(jù)保護(hù):工作負(fù)載的可恢復(fù)性
- 隱私計算:推進(jìn)數(shù)據(jù)“可用不可見”的關(guān)鍵技術(shù)
- Mastering Malware Analysis
- 網(wǎng)絡(luò)安全監(jiān)控實戰(zhàn):深入理解事件檢測與響應(yīng)
- 企業(yè)安全建設(shè)入門:基于開源軟件打造企業(yè)網(wǎng)絡(luò)安全
- 大數(shù)據(jù)時代的智慧城市與信息安全
- 云原生安全