What if the expression of a while loop never evaluates to false?   In this case the program will loop over and over again until you physically stop it.  Programmers call this an infinite loop.   We can simulate this by using the keyword ‘true’ as an expression.   True represents what it says – it will never become false.

Tasks:

There is also a ‘false’ keyword.   It always evaluates to false and will never become true.

Tasks:

Sometimes it is more convenient to program an expression that evaluates to the opposite of what we want and then tell the compiler we want the opposite again.   We do this with the ! symbol and we place it before the expression we want the opposite of.   ! turns a true expression into a false one, and a false one into a true one.   Programmers call this symbol a ‘not’, so when you see the expression !true you can pronounce it as ‘not true’.

This expression Is the same as
true true
!true false
false false
!false true

Tasks:

There are other sorts of expressions that cause an infinite loop, we don’t have to explicitly state that an expression is true.   All we need is an expression that is true and can never become false.   For example we could use the expression 1 == 1.   One is equal to 1, so this is true.   1 can never be equal to anything other than 1, so the expression will never change.

Tasks: