How do I repeat a piece of code
Here you can use a loop. a classic for loop in C++ looks like this 

for (int i = 0; i &lt; n; i++)
{
    // content in between these brackets
}


where n is the amount of times you want to loop

you can also instantiate the i before the loop.

int i;
for (i = 0; i &lt; n; i++)
{
    //content here
}


The code below should work. Toy around with it and see what you get.

int ledPin = 13;
int delayPeriod = 500;


void setup(){
    pinMode(ledPin, OUTPUT);

    for (int i = 0; i &lt; 3; i++){
        digitalWrite(ledPin, HIGH);
        delay(delayPeriod);
        digitalWrite(ledPin, LOW);
        delay(delayPeriod);
    }


another approach you can do is using a while loop. These kinds of loops will loop until a given parameter has been met. In your case you want an LED to stop blinking after 3 times. 

int start = 0;
int stop = 3;

while (start &lt;= stop){
    //content here
}


While loops will continue to go as long as the parameter is true. This means something like while(1) will continue to run forever.