Need help to solve error

I am a newbie, trying to make a Line Following Obstacle Avoidance Robot
I tried combining parts of 2 pre-done code.Everything seems well now,but this error pops up.
:103:3:Error: expected unqualified-id before 'if'

Project_DIY_065.ino (3.8 KB)

  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
}

if (distance < stop_distance)

You have code outside of a function

Auto format in the IDE and putting each { and } on its own line (as I did) will show up the problem

...and for future reference, if you really want help, post your code, don't attach it.