A robot for performing endoscopic procedures in flexible and curved human or animal lumens. A plurality of segments are attached to each other. Traction segments embrace the lumen walls. Other segments include actuators that cause the endoscope to locally deform its shape via bending, extending, or some combination of bending and extension. A method is provided to sequence the action of the segments to cause inchworm-like or snake-like locomotion, or a combination of them through a curved and flexible lumen. The method of movement can be adapted to the lumen characteristics, or to obviate a component failure. A compressed gas line attached to the back segment provides compressed gas for insufflation of the lumen, and can optionally be used to drive the actuators that control the operation of the endoscope segments. The lead segment may include television cameras, ultrasound transducers, biopsy arms, drug delivery systems, or other sensors, diagnostic aids, therapeutic devices, and surgical tools. Medical instruments and sensors can also be placed in the rear or middle segments.