Arduino resetting itself!

When I turn my Arduino on it runs the program but then instead of looping on "void loop" function it restarts from void setup...
Please help...by telling me how to solve this problem...

This is the code I am running...

#include <Servo.h>

int LedPin1 = 12;
int LedPin = 13;
int MotorPin1 = 9;
int MotorPin2 = 10;
int servoPin = 6;

Servo VishalServo;

void setup()
{
digitalWrite(LedPin, HIGH);
Serial.begin(9600);
pinMode(LedPin, OUTPUT);
pinMode(LedPin1, OUTPUT);
pinMode(MotorPin1, OUTPUT);
pinMode(MotorPin2, OUTPUT);
VishalServo.attach(servoPin);
VishalServo.writeMicroseconds(1500);
delay(2000);
}

void loop()
{
while (Serial.available() == 0);
int val = Serial.read() - '0';

int i = VishalServo.read();

if (val == 2)
{
Serial.println("Robot is On");
digitalWrite(MotorPin1, HIGH);
digitalWrite(MotorPin2, HIGH);
delay (500);
digitalWrite(MotorPin1, LOW);
digitalWrite(MotorPin2, LOW);
delay(5);
}

if (val == 1)
{
Serial.println("Robot is turning left");
digitalWrite(MotorPin2, HIGH);
delay(500);
digitalWrite(MotorPin2, LOW);
delay(5);
}

if (val == 3)
{
Serial.println("Robot is turning right");
digitalWrite(MotorPin1, HIGH);
delay(500);
digitalWrite(MotorPin1, LOW);
delay(5);
}

if (val == 9)
{
Serial.println("Turning left");
VishalServo.write(i+5);
delay(5);
}

if (val == 7)
{
Serial.println("Turning right");
VishalServo.write(i-5);
delay(5);
}

if (val == 5)
{
Serial.println("Shoot");
digitalWrite(LedPin1, HIGH);
delay(50);
digitalWrite(LedPin1, LOW);
delay(5);
}

if (val == 8)
{
Serial.println("Centering");
VishalServo.writeMicroseconds(1500);
delay(5);
}

else
{
delay(5);
}
}

And I am using putty as the terminal program as well as the arduino terminal program...but the problem occurs in both of them.

Thanks

I'd disable the autoreset for starters and see if that makes a difference. A small electrolytic capacitor of somewhere between 1uF & 47 uF between reset and gnd works well.........

Nope it doesn't work

Suppose I clicked 2 and the motors are still running and i click 2 again when the motors are running, then the arduino resets.

And when I click 1 and 2 then the power LED blinks very quickly, does that have anything to do with this.
Thanks

How are you powering your board? If powering the servo from the board's +5vdc, that can often lead to problems.

Lefty

The servo is powered separately and the board is powered off the computer.