Animation rotates to closest angle
When you rotate an object visually in the 3Dview, the rotation value that is used is not always the value you expect. You can get more predictable results by entering values directly in the properties of the object, which can also be found in the properties sidebar by pressing N



When you do have trouble with direction of rotation (or movement), the graph editor shows you visually how the values are interpreted and gives you full control over the keyframed values.

In this example the rotation goes to 180 then back to 0



By adjusting the third keyframe we change it to go to 180 then to 360



You can also change the channels extrapolation (ShiftE or Channel->Extrapolation Mode) to linear and have a constant rotation with only two keyframes.