Problem solved

It checks the state of pin 12 and while it is HIGH (true) it alternates the state of pin 2 between HIGH and LOW every 1000 milliseconds

Formatting the code better may make its structure easier to see

int beginTime = 0;

void setup()
  pinMode(12, INPUT_PULLUP);
  pinMode(2, OUTPUT);

void loop()
  while (digitalRead(12))
    digitalWrite (2, !digitalRead(2));  //read the state of pin 2.  Invert it and write it back to pin 2
    beginTime = millis();
    while (millis() < beginTime + 1000) {}
  digitalWrite (2, LOW);

Note that you can read the state of a pin set to OUTPUT

Problem solved

It is very bad manners to delete your question.

When you solve a problem the proper response is to tell what you did so others can learn.


I fully endorse what Robin says. The forum not only provides a means of getting help with individual problems but also a valuable resource for other Arduino users who may have the same or similar problems but by deleting your original post and not sharing the solution you have prevented it providing help to others