***** Does not name a type

I'm trying to create a program that will run a stepper motor until it hits a microswitch. Once it hits the microswitch I need it to then move in the opposite direction. I've got the motor to stop once it hits the microswitch, but I'm running into problems running the motor after that.

I'm using the same "myMotor->step ()" function that I use to initially move the stepper, but now I get the error "myMotor does not name a type."

I've attached my code below. Any help would be greatly appreciated!

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include <Servo.h>
#include <AccelStepper.h>
#include "Arduino.h"


Adafruit_MotorShield AFMS = Adafruit_MotorShield();

Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 1);


int i=0;
int pin=2;
void setup() {
  AFMS.begin();
  Serial.begin(9600);

  myMotor->setSpeed(100);
 Serial.println("yeet");

while (i<100){
  i=analogRead(2);
  Serial.print("i=");
  Serial.println(i);
  myMotor->step(10,FORWARD,SINGLE);
}
 }
  
[b] myMotor->step(10,FORWARD,SINGLE);[/b]

  void loop() {}

I'm going to guess that you didn't install Adafruit_MotorShield library correctly.

Please post the whole error message.

Edit: your highlighted code is not in a function.
You need to fix that.

steppermove:34: error: 'myMotor' does not name a type

myMotor->step(10,FORWARD,SINGLE);

^

Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire
Using library Adafruit_Motor_Shield_V2_Library_master at version 1.0.5 in folder: C:***********************************
Using library Servo at version 1.1.2 in folder: C:\Program Files (x86)\Arduino\libraries\Servo
Using library AccelStepper in folder: C:***************************************
(legacy)
exit status 1
'myMotor' does not name a type

Please see my edit to my first reply.

(deleted)