- 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.
- Extending Symfony2 Web Application Framework
- Web漏洞分析與防范實(shí)戰(zhàn):卷1
- INSTANT Netcat Starter
- 工業(yè)互聯(lián)網(wǎng)安全
- 網(wǎng)絡(luò)空間攻防技術(shù)原理
- Learning Python for Forensics
- CSO進(jìn)階之路:從安全工程師到首席安全官
- 深入淺出隱私計(jì)算:技術(shù)解析與應(yīng)用實(shí)踐
- 硬黑客:智能硬件生死之戰(zhàn)
- 計(jì)算機(jī)網(wǎng)絡(luò)安全技術(shù)研究
- 網(wǎng)絡(luò)安全與攻防入門很輕松(實(shí)戰(zhàn)超值版)
- 網(wǎng)絡(luò)安全實(shí)戰(zhàn)詳解(企業(yè)專供版)
- 計(jì)算機(jī)網(wǎng)絡(luò)安全實(shí)驗(yàn)指導(dǎo)
- 紅藍(lán)攻防:技術(shù)與策略(原書第3版)
- 動(dòng)態(tài)賦能網(wǎng)絡(luò)空間防御