Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Conditions in a programming language are instructions that direct the flow of a program. This works a bit like rail traffic: a train travels on a rail until it hits a switch, then the train changes its direction of travel. Conditions, therefore, change the course of a program. But how is the direction actually decided? The answer to this is logical operations based on the Boolean logic (remember the logic gates exercise?) . We use logical operations in everyday life, here are some examples:

...

Code Block
int x=10;
switch(x)
{
case 10:
println("x is the same as 10");
break;
case 9:
println("x is the same as 9");
break;
case 8:
println("x is the same as 8");
break;
default:
println("x is the same as 10,9 or 8");
break;

Exercise 5

Programm a Program a drawing app. The colour can be changed with the buttons '1' - '5'. The left mouse button draws and the right mouse button erases the drawing.

...