wall avoidance algorithm?

I build a small robot and have come up with some very basic wall avoidance code that works OK.

the basic loop i came up with is: (I think the function names are pretty self explanitory but the full code is at my other post http://arduino.cc/forum/index.php/topic,109076.0.html if you want to look)

void loop()
{
  directionalPing();
  if(pingLeft <= 6)
    {
      reverse(50);
      turnRight(600);
      return;
    }
  if(pingRight <= 6)
    {
      reverse(50);
      turnLeft(600);
      return;
    }
  if(pingForward <= 6)
    {
      reverse(200);
      turnLeft(600);
      return;
    }
  if(pingForward > 6)
    {
      reverse(50);
      forward(150);
      return;
    }
}

Im pretty new to programming and I am sure there is a better way to do something like this than to run exhaustive if statements. Im not looking for code handouts, but I have been looking on them tharr interwebs for solutions and i guess I just dont know what to look for. Any code specific or general learning advice would be greatly appreciated.

If it works OK then there no need to mess with it.

instead of a long list of if statements you can usually use switch: http://arduino.cc/en/Reference/SwitchCase

however, I think in your case it would only make things more confusing. The only thing odd that I found in your code is this part:

  if(pingForward > 6)
    {
      reverse(50);
      forward(150);
      return;
    }

are you telling your robot to go backwards and then forwards?

fkeel:
are you telling your robot to go backwards and then forwards?

sort of, it doesn't actually go backwards, just puts a but of extra stopping power in there, in the current code it goes forwards then backwards(as an extra brake, the brake function on the motor sheild r3 doesnt seem to do a whole lot with these motors)

johnwasser:
If it works OK then there no need to mess with it.

if it was a tool, or something that did a job I could see the logic of that, but as something that just drives around my kitchen, that was put together to learn, I see it working ok as exactly the reason to mess with it