'motor1' does not name a type

I am very new at coding, can you help me understanding what this error means? Thank you

#include <AFMotor.h>
AF_DCMotor motor1(1, MOTOR12_64KHZ);
motor1.setSpeed(255);
void loop() {
  motor1.run(FORWARD);
  delay(1000);
  motor1.run(BACKWARD);
  delay(1000);
  motor1.run(RELEASE);
  delay(1000);
}
motor1.setSpeed(255);

It means that line has to be inside a function. Put it in setup.