Counting loops

Hey. im creating a robot with a ultrasonic sensor and two DC motors. I have the robot programmed to drive straight until it detects a wall a certain distance away. Once it detects the wall i made the robot turn right and i have the code return to the void loop where it determines weather how far the wall away is. I wanted to use a boolean statement where it states that the wall is a certain distance away and (&&) a specific loop was ran once. Can the code count how many times a loop was ran and if so how do you code it in the program using boolean

Can the code count how many times a loop was ran

Yes.

unsigned long loopCount = 0;

void loop()
{
   loopCount++;

   // Do other stuff
}

Do not expect the value in loopCount to mean anything, though.

if so how do you code it in the program using boolean

How do YOU count using true and false?

PaulS:
How do YOU count using true and false?

void loop() {
  static boolean isOdd = false;
  isOdd = !isOdd;
  if(!isOdd) Serial.println("Even numbered loop!");
}