while Statement is very flexible , It can be used to repeatedly execute code blocks when the condition is true .
Is a sequence ( Or other iteratable objects ) Each element in the executes a code block .
Use keys Wait for the dictionary method to get all the keys . If you're only interested in values , You can use d.values .
Iterating over several sequences simultaneously
Get the index of the current object while iterating the object sequence
reversed and sorted . They are similar to list methods reverse and sort ( sorted The accepted parameters are also related to sort similar ), But it can be used for any sequence or iteratable object , And do not modify the object in place , Instead, it returns the inverted and sorted version .
To end ( Jump out of ) loop , You can use break.
It ends the current iteration , And skip to the beginning of the next iteration .
while True Cause the cycle to never end , But you put the condition in one of the loops if In the sentence , And this one if Statement will call... When the condition is met break .
Add a line to the loop else Clause , It's only when... Is not called break Execution only .
author : Programming workshop
Game programming , A game development favorite ~
If the picture is not displayed for a long time , Please use Chrome Kernel browser .