Schleifen: while4 / 5

break: raus, sobald es passt.

solange.py
python
1geheim = 7
2while True:
3tipp = int(input("Zahl? "))
4if tipp == geheim:
5print("Richtig!")
6break
7print("Nochmal!")
Ausgabe
Zahl? 3Nochmal!Zahl? 9Nochmal!Zahl? 7Richtig!

while True läuft eigentlich für immer. break beendet die Schleife sofort – hier, sobald der Tipp stimmt.

19.3/60