Error Messages in code

Hi, i have these error messages and wondering what i have done wrong, and how to change it,
thanks for any help!

int latchPin = 8;  //Pin connected to Pin 12 of 74HC595 (Latch)
int clockPin = 12; //Pin connected to Pin 11 of 74HC595 (Clock)
int dataPin = 11;  //Pin connected to Pin 14 of 74HC595 (Data)
void setup() {
        //set pins to output
}
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
void loop() {
        for (int i = 0; i < 256; i++) {     //count from 0 to 255
} }
digitalWrite(latchPin, LOW); //set latchPin low to allow data flow
shiftOut(i);
shiftOut(255-i);
//set latchPin to high to lock and send data
digitalWrite(latchPin, HIGH);
delay(250 );
void shiftOut(byte dataOut) {
        boolean pinState; // Shift out 8 bits LSB first, on rising edge of clock
        digitalWrite(dataPin, LOW); //clear shift register ready for sending data
        digitalWrite(clockPin, LOW);
        for (int i=0; i<=7; i++)  {  // for each bit in dataOut send out a bit
        digitalWrite(clockPin, LOW); //set clockPin to LOW prior to sending bit
// if value of DataOut and (logical AND) a bitmask are true, set pinState to 1 (HIGH)
                if ( dataOut & (1<<i) ) {
}
        pinState = HIGH;
}
else {
}
pinState = LOW;
        //sets dataPin to HIGH or LOW depending on pinState
        digitalWrite(dataPin, pinState);
        digitalWrite(clockPin, HIGH); //send bit out on rising edge of clock
        digitalWrite(dataPin, LOW);
}
digitalWrite(clockPin, LOW); //stop shifting

Here are my errors:

Code.ino:7:8: error: expected constructor, destructor, or type conversion before '(' token
Code.ino:8:8: error: expected constructor, destructor, or type conversion before '(' token
Code.ino:9:8: error: expected constructor, destructor, or type conversion before '(' token
Code.ino:13:13: error: expected constructor, destructor, or type conversion before '(' token
Code.ino:14:9: error: expected constructor, destructor, or type conversion before '(' token
Code.ino:15:9: error: expected constructor, destructor, or type conversion before '(' token
Code.ino:17:13: error: expected constructor, destructor, or type conversion before '(' token
Code.ino:18:6: error: expected constructor, destructor, or type conversion before '(' token
Code.ino: In function 'void shiftOut(byte)':
Code.ino:30:1: error: 'else' without a previous 'if'
Code.ino: At global scope:
Code.ino:38:13: error: expected constructor, destructor, or type conversion before '(' token
Error compiling.
void setup() {
        //set pins to output
}
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);

The close } goes AFTER the code that belongs IN the function. The comment is useless as far as making anything happen.

So I change that to:

void setup() {
        //set pins to output

pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

And i still get other error messages:

Code.ino:14:13: error: expected constructor, destructor, or type conversion before '(' token
Code.ino:15:9: error: expected constructor, destructor, or type conversion before '(' token
Code.ino:16:9: error: expected constructor, destructor, or type conversion before '(' token
Code.ino:18:13: error: expected constructor, destructor, or type conversion before '(' token
Code.ino:19:6: error: expected constructor, destructor, or type conversion before '(' token
Code.ino: In function 'void shiftOut(byte)':
Code.ino:31:1: error: 'else' without a previous 'if'
Code.ino: At global scope:
Code.ino:39:13: error: expected constructor, destructor, or type conversion before '(' token
Error compiling.

Same here :

else {
}
pinState = LOW;
        //sets dataPin to HIGH or LOW depending on pinState
        digitalWrite(dataPin, pinState);
        digitalWrite(clockPin, HIGH); //send bit out on rising edge of clock
        digitalWrite(dataPin, LOW);

And here

void loop() {
        for (int i = 0; i < 256; i++) {     //count from 0 to 255
} }

Must be :

if ( something )
{
 do_something;
 }

else 
{
 do_something_else
}

Same with functions :

void loop()
{                                   \\ opening loop() function
some_code;
.....
.....
   if ( something )
   {
     do_something;
    }

   else 
   {
     do_something_else
   }
....
....
}                               // closing loop() function

Thanks, I’ve altered to my best ability the code from your comments,

int latchPin = 8;  //Pin connected to Pin 12 of 74HC595 (Latch)
int clockPin = 12; //Pin connected to Pin 11 of 74HC595 (Clock)
int dataPin = 11;  //Pin connected to Pin 14 of 74HC595 (Data)
void setup() {
        //set pins to output

pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
        for (int i = 0; i < 256; i++) {     //count from 0 to 255
 
digitalWrite(latchPin, LOW); //set latchPin low to allow data flow
shiftOut(i);
shiftOut(255-i);
//set latchPin to high to lock and send data
digitalWrite(latchPin, HIGH);
delay(250 );
}}
void shiftOut(byte dataOut) {
        boolean pinState; // Shift out 8 bits LSB first, on rising edge of clock
        digitalWrite(dataPin, LOW); //clear shift register ready for sending data
        digitalWrite(clockPin, LOW);
        for (int i=0; i<=7; i++)  {  // for each bit in dataOut send out a bit
        digitalWrite(clockPin, LOW); //set clockPin to LOW prior to sending bit
// if value of DataOut and (logical AND) a bitmask are true, set pinState to 1 (HIGH)
         
if ( dataOut & (1<<i) ) {

        pinState = HIGH;
}}
else {

pinState = LOW;
        //sets dataPin to HIGH or LOW depending on pinState
        digitalWrite(dataPin, pinState);
        digitalWrite(clockPin, HIGH); //send bit out on rising edge of clock
        digitalWrite(dataPin, LOW);

digitalWrite(clockPin, LOW); //stop shifting
}}

But have this: (I think I may have not changed something right…)

Code.ino: In function 'void shiftOut(byte)':
Code.ino:33:1: error: 'else' without a previous 'if'
Error compiling.

Look againg. Same problems with { and } in wrong places . You really must look at some code examples - open few from Arduino IDE : FILE -> EXAMPLES .

Code.ino:33:1:

This gives you some hint - the problem might be in line number 33 ....

Start by putting every { on a new line:

void setup()
{

NOT

void setup() {

Then, ONE } per line. NEVER more than one. NOTHING else on the same line.

Next, use the Tools + Auto Format menu item, to properly indent your code.

Now, does your else statement match an if statement? The compiler (correctly) says no.

I dont understand whats wrong with my if & else statement

int latchPin = 8;  //Pin connected to Pin 12 of 74HC595 (Latch)
int clockPin = 12; //Pin connected to Pin 11 of 74HC595 (Clock)
int dataPin = 11;  //Pin connected to Pin 14 of 74HC595 (Data)

void setup()
{
  //set pins to output

  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

}
void loop()
{
  for (int i = 0; i < 256; i++)
  { //count from 0 to 255

    digitalWrite(latchPin, LOW); //set latchPin low to allow data flow
    shiftOut(i);
    shiftOut(255 - i);
    //set latchPin to high to lock and send data
    digitalWrite(latchPin, HIGH);
    delay(250 );

  }
}
void shiftOut(byte dataOut)
{
  boolean pinState; // Shift out 8 bits LSB first, on rising edge of clock
  digitalWrite(dataPin, LOW); //clear shift register ready for sending data
  digitalWrite(clockPin, LOW);
  for (int i = 0; i <= 7; i++)
  { // for each bit in dataOut send out a bit
    digitalWrite(clockPin, LOW); //set clockPin to LOW prior to sending bit
    // if value of DataOut and (logical AND) a bitmask are true, set pinState to 1 (HIGH)

    if ( dataOut & (1 << i) )
    {

      pinState = HIGH;
    }
  }
  else
  {

    pinState = LOW;
    //sets dataPin to HIGH or LOW depending on pinState
    digitalWrite(dataPin, pinState);
    digitalWrite(clockPin, HIGH); //send bit out on rising edge of clock
    digitalWrite(dataPin, LOW);

    digitalWrite(clockPin, LOW); //stop shifting
  }
}

Errors:

Code.ino: In function 'void shiftOut(byte)':
Code.ino:44:3: error: 'else' without a previous 'if'
Error compiling.
    if ( dataOut & (1 << i) )
    {
      pinState = HIGH;
    }
  } // Hint: What is this brace closing?

Make an attempt to use Auto Format.
If it does not work due to unmatched / mismatched code go thru each block of code and set up your cursor around each first bracket ( here { or here ) and see if the last MATCHING bracket is where you expect it.
This “block detector” is rather unreliable and if you combine it with mouse click it will also highlight the matching block.

It is better to start “inside out” to find the mismatched block.

Here is a good , original post , candidate.

if ( dataOut & (1 << i) )
    {
block of code start 
      pinState = HIGH;
block of code end 
    }
 

  }  mismatch 
  else

  {
block of code start 
    pinState = LOW;
    //sets dataPin to HIGH or LOW depending on pinState
    digitalWrite(dataPin, pinState);
    digitalWrite(clockPin, HIGH); //send bit out on rising edge of clock
    digitalWrite(dataPin, LOW);

    digitalWrite(clockPin, LOW); //stop shifting
block of code end    
  }


}

Instead of trying to guess where the brackets go, or just putting them where you think they might go, please go look at some examples or tutorials on C++ and try to learn how they work so you'll KNOW where they need to go.