c# - break does not seem to return to previous loop -


i programming robot c# , using digitial compass direction. problem having when goes turn loop, doesnt come out of it. dragonboard controller talking too. how supposed work given set heading , time, turns left or right till heading matched drives forward set amount of time. problem having go forward when goes turn loop, stays there, , doesnt return loop. appreciated.

private void drive(int heading, int time)//going start kit {     int i;      (i = 0; < time;i++ )     {         dragonboard.write("w");//go forward          while (int.parse(bearingtxt.text) - 1 > heading)         {             dragonboard.write("a");//turn left             break;         }          while (int.parse(bearingtxt.text) +1 < heading)         {             dragonboard.write("d");//turn right             break;         }     }      dragonboard.write(" ");      if (listbox1.selectedindex < listbox1.items.count - 1)     {         listbox1.selectedindex = listbox1.selectedindex + 1;         decision();     } 

it because break exits "while loop" not loop...and im guessing while loop executes once? why need while that? try this

 (i = 0; < time;i++ ) {     dragonboard.write("w");//go forward      if (int.parse(bearingtxt.text) - 1 > heading)     {         dragonboard.write("a");//turn left         break;     }      else (int.parse(bearingtxt.text) +1 < heading)     {         dragonboard.write("d");//turn right         break;     } } 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -