Pages: [1]   Go Down
Author Topic: break  (Read 283 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

part of code
Quote
void rec_tab(){
  byte i=0,chk=0,j=0;
    while(1){
    if (Serial.available()>0){
      in_buff[j] = Serial.read();
      chk^=in_buff[j]; 
      j++;  
      if (j==in_buff[1]+2) break;

      lcd.setCursor(0,1);
      lcd.print(chk,HEX);
    }
  }
  lcd.setCursor(0,0);
  lcd.print("  after break ");
  lcd.print(chk,HEX);
}


Why break clear chk ??
Before break LCD display 0xA3  after break 0x00 ??

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tried posting down the street at snippets-r-us.com? Here, we get to see ALL of your code, posted using the code icon (with the #), not the quote icon.
Logged

0
Offline Offline
Shannon Member
****
Karma: 207
Posts: 12205
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

break isn't clearing chk, your code is changing it.  break exits the innermost enclosing loop or switch statement with immediate effect.
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Edison Member
*
Karma: 33
Posts: 1447
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

break does not break out of "ifs", only loops. Your break leaves the while loop.
Logged

Pages: [1]   Go Up
Jump to: