Program stops in the loop.

This is an extract of my programm:

void loop(){

if (state==0){

// Serial.println ( “Bitte geben Sie den 11 stelligen Code ein”);
while (Serial.available() <= 10) {

}

//delay(100);
Alts1old=Alts1;
Alts2old=Altst2;
Alts3old=Altst3;
Alts4old=Altst4;
Alts5old=Altst5;
Alts6old=Altst6;
Alts7old=Altst7;
Alts8old=Altst8;
Alts9old=Altst9;
Alts10old=Altst10;
Alts11old=Altst11;

//Serial.println(Serial.available());

//Hier werden die 11 Zeichen eingelesen

Alts1=(Serial.read()-48);
Altst2=(Serial.read()-48);
Altst3=(Serial.read()-48);
Altst4=(Serial.read()-48);
Altst5=(Serial.read()-48);
Altst6=(Serial.read()-48);
Altst7=(Serial.read()-48);
Altst8=(Serial.read()-48);
Altst9=(Serial.read()-48);
Altst10=(Serial.read()-48);
Altst11=(Serial.read()-48);

delay(500);
Serial.println(Alts1);
Serial.println(Altst2);
Serial.println(Altst3);
Serial.println(Altst4);
Serial.println(Altst5);
Serial.println(Altst6);
Serial.println(Altst7);
Serial.println(Altst8);
Serial.println(Altst9);
Serial.println(Altst10);
Serial.println(Altst11);
Serial.println(“eingelesen”);

if (Alts1==0 && Altst2==0 && Altst3==0 && Altst4==0 && Altst5==0 && Altst6==0&& Altst7==0&& Altst8==0&& Altst9==0&& Altst10==0&& Altst11==0 ){
Serial.println ( “Stoppfunktion! Sie befinden sich nun wieder im Initialzustand!”);
state=0;

.
.
.

The Output is:

IO-Monitor ist bereit und wartet auf eine Eingabe
0
0
0

After this the program stops und I have to reset ist.

I hope somebody can help me to solve the problem.

Markus

    while (Serial.available() <= 10) {

    }

Do nothing until there are at least to bytes. When this loop ends, there will be exactly 10 bytes. So, then:

    Alts1=(Serial.read()-48);
    Altst2=(Serial.read()-48);
    Altst3=(Serial.read()-48);
    Altst4=(Serial.read()-48);
    Altst5=(Serial.read()-48);
    Altst6=(Serial.read()-48);
    Altst7=(Serial.read()-48);
    Altst8=(Serial.read()-48);
    Altst9=(Serial.read()-48);
    Altst10=(Serial.read()-48);
    Altst11=(Serial.read()-48);

You read all 11 of them. How is that working out for you? Oh, wait. Never mind. I already know.

Have you ever heard of arrays? http://arduino.cc/en/Reference/Array
For loops? http://arduino.cc/en/Reference/For

This is an extract of my programm

It is not a snippet of your code that fails. It is ALL of your code that fails. Therefore, you need to post ALL of your code.

In my personal opinion it may be best to read one byte at a time or have it look for a particular EOF value because in the event of some corruption there may be more or less than 10 bytes available and your code may not contain all valid data. I'd recommend a particular pattern or start-byte and then a particular pattern or EOF byte and have it pull the data when it sees these two match.

Maybe someone has an even better idea but that's just something that crossed my mind. I have a similar project I'm coding for and it looks for commands sent by serial, and everytime a byte is available it appends it to an array or a string. Then when it sees an EOF it looks at what's in the string/array and processes what it needs to process then resets a position counter variable.