The locomotory behavior of Caenorhabditis elegans consists of four simple events, forward and backward movements, omega-shaped turns and rests. The wide variety of behaviors of this worm is achieved through a combination of these simple locomotions. To gain insight into the neuronal mechanisms regulating this locomotion, we analyzed the locomotory behavior of C. elegans over a long time period. By using an automatic worm tracking system, we revealed the existence of at least two distinct behavioral states -- pivoting and traveling -- in the forward locomotion of C. elegans in the absence of food. Pivoting is characterized by pronounced directional switching and resulting in short-duration forward movement, whereas in the traveling state forward movement is of longer duration. Pivoting occurred when we transferred a well-fed worm to an unseeded plate, and then the transition to traveling occurred, successively. We showed that, by laser ablation, antagonistic neuronal pathways consisting of nine classes of sensory neurons and four classes of interneurons were involved in this regulation. Loss of any one of these neurons altered the locomotory behavior.