Making decisions:

Once you’ve got your led flashing and words printing on screen, you may want to add a bit of sophistication.

For example only switch your led on when a button is pressed, or print a different sentence.

To do this you will use an if statement:

If(the thing that you want to check)

{

  if its true, these instructions will run

}

else

{

 if its not true, these instructions will run instead.

}

Also, there will be times when you want to repeat the same set of instructions and instead of writing them out lots of times you can use the for statement.

For(int i=0; i<8; i++)

{

 repeat these instructions 8 times

}

This may seem a bit confusing at first, so lets break it up:

For( int I =0;  This part is the beginning of the for loop, and it starts by declaring an integer variable. You need this variable to act as a counter.

The next part:

 i<8; while our integer i is less than 8

i++  add one to i

So, as long as i is less than 8, it will repeat the instructions that are between the curly brackets.

As soon as i is equal to 8, it will stop and move on to the next part of the code.

The best way to get your head round this is to write a program that uses a for loop and play around with it.