if else loop issues

Your IDE has Example Sketches built right in and you want to work your way through section 05.Control.
Start in the IDE by getting the File dropdown menu and click Examples->05.Control and start with the first and work your way through until you understand what each part does because so far, you don't and seeing working code should help you the most.

HOWEVER, you can line by line explanations of your Examples sketches through this page:

You really need to go through section 5 if you can.