ThePythonGameBook

learn Python. Create Games

User Tools

Site Tools


en:python:goblins:step006

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:python:goblins:step006 [2013/07/24 12:37]
Horst JENS [expression]
en:python:goblins:step006 [2019/05/02 10:26]
Horst JENS
Line 21: Line 21:
 so let me explain instead: so let me explain instead:
  
-The while loop is used when you do not know in how many times to loop, but when you know when to stop looping. You can give such an [[http://​docs.python.org/​3/​reference/​expressions.html#​grammar-token-expression|condition or expression]] at the start of the loop as well as inside the loop.+The while loop is used when you do not know in how many times to loop, but when you know when to stop looping. You can give such an [[http://​docs.python.org/​3/​reference/​expressions.html#​grammar-token-expression|boolean ​condition or expression]] at the start of the loop as well as inside the loop.
  
  
Line 69: Line 69:
 === condition at start of while loop === === condition at start of while loop ===
  
-Now with the knoledge ​of expressions you can construct a while loop. The while loop will loop as long as the expression remains True. If the expression is never True the while loop will not even start. Be careful:+Now with the knowledge ​of expressions you can construct a while loop. The while loop will loop as long as the expression remains ​''​True''​. If the expression is never ''​True'' ​the while loop will not even start. Be careful:
  
-The expression will only be checked at the beginning of each loop, not inside the loop ( when computing the indented commands below the line with the colon ). If you need to make such checks in the middle of each loop, you need an **if** statement to **break** out of the loop.+The expression will only be checked at the beginning of each loop, not inside the loop ( when computing the indented commands below the line with the colon ). If you need to make such checks in the middle of each loop, you need an **''​if''​** statement to **''​break''​** out of the loop.
  
 === if statement == === if statement ==
  
-What is an if statement ? It is a logical structure that you can find in nearly every programming language, also called an conditional. It will only computer certain commands **if** an condition is met ( an ''​expression''​ is ''​True''​ ) and will otherwise do nothing or compute commands below an **else** statement.+What is an ''​if'' ​statement ? It is a logical structure that you can find in nearly every programming language, also called an conditional. It will only computer certain commands **if** an condition is met ( an ''​expression''​ is ''​True''​ ) and will otherwise do nothing or compute commands below an **else** statement.
  
 Let's take an look at the [[http://​docs.python.org/​3/​reference/​compound_stmts.html#​the-if-statement|offical python documentation]]:​ Let's take an look at the [[http://​docs.python.org/​3/​reference/​compound_stmts.html#​the-if-statement|offical python documentation]]:​
/var/www/horst/thepythongamebook.com/data/pages/en/python/goblins/step006.txt ยท Last modified: 2019/05/02 10:26 by Horst JENS