changing dc motor direction with two switches

Hello, I'm pretty new to Arduino, I have got them going in some quite complex projects, however I am having quite a lot of trouble getting the code right in what I thought would be a very simple one. I am running a dc motor with the arduino through two relays so that if I set one pin high the motor runs one direction, and set the other pin high the motor reverses. I also have two magnetic switches that when the shaft reaches the end the switch is hit and the motor reverses after a five second pause. I thought this would be a very simple program however without an "until" statement it seems alot more complex then I thought. I have tried several different versions of the program below, however if it runs at all, the motor will just keep running in the one direction even after the switch has been triggered. This is the latest version of code I've tried with no success:

#define motorpin1 7
#define motorpin2 8

const int sensorpin1 = 3;
const int sensorpin2 = 5;
int sensor1 = 0;
int sensor2 = 0;

void setup() {

pinMode(motorpin1, OUTPUT);
pinMode(motorpin2, OUTPUT);
pinMode(sensorpin1, INPUT);
pinMode(sensorpin2, INPUT);

// Initialize the Serial port:
Serial.begin(9600);

}

void loop() {

sensor1 = digitalRead(sensorpin1);

do
{
digitalWrite (motorpin1, HIGH);

} while (sensor1 == LOW);

if (sensor1 == HIGH)
{digitalWrite (motorpin1, LOW);
delay (5000);
}

sensor2 = digitalRead(sensorpin2);

do
{
digitalWrite (motorpin2, HIGH);
} while (sensor2 == LOW);

if (sensor2 == HIGH)
{digitalWrite (motorpin2, LOW);
delay (5000);
}
}

I was expecting to be able to use something like an "until" statement so the program could be something simple like:
set pin 1 high until switch 1 goes high
then set pin 1 low and set pin2 high until switch 2 goes high

Like I said I'm new to this so there is probably something quite simple that I have overlooked, so any help you could provide would be greatly appreciated, especially if you know of a much simpler way what I'm after could be achieved.

In your very first loop there's no 'read' to change the value of 'sensor1'
If it reads LOW first time, the loop will never exit.