code repeat???

Status
Not open for further replies.

gatoulisss

New Member
hello guys!
is there any way of repeat this code line without writing them?

delay_ms(5000);
if (porta.f0==0) {goto start;}

because if i write it the programm crashes i dont know why... maybe the delay times are too big
 
You can try the program in PicBasicPro or other BASIC and I think it should work, assuming "start" is a label at delay_ms. Does C support "goto"? I doubt it....

Allen
 
Last edited:
On second thought, I think I dont understand what the OP was asking..

Allen
 
Without knowing where start is, it's hard to advise but the normal method is,
Code:
while(1){                         //loop forever
    delay_ms(5000);
    if (porta.f0==0)
        {/*do something here*/}
} //end while loop

Mike.
Edit, got my remarks mixed up.
 
Last edited:
Yeah, goto's are highly discouraged in C, due to the fact that it makes readability of the code difficult. Its hard to track flow, which impacts maintainability.

Like Pommie suggests, rather write it like that, and make START a function or similar.
Code:
void start(void) {
/* many 'start' things */
}

int main (void) {
  while(1){                       
    delay_ms(5000);
    if (porta.f0=0) {
      start();
    }
  }
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…