For loop

be80be

Well-Known Member
If i use a for loop my C not that great lol but if I figure this out I think i got it
Code:
for (; ;) {
        for int (i = 0;  i< 100 ; i++) {
       }
     return 0;   // this starts all over?  wrong or Right?
}
I can't find much how it works in xc8 guess I could just try it lol
 
You need the int inside the brackets.
for(int i=0;i<100;i++){

You probalby want to change it to unsigned int so it's quicker.

Edit, you do not want to return from main.

Mike.
 
This does what I think it start the loop all over
Code:
void main(void) {
    OSCCON = 0b01110110;
    for (; ;) {
      
        for(unsigned int i = 0;  i< 100; i++) {
       }
       return; // this starts all over?  wrong or Right?
}
  
}
I was messing with some LCD code that had returns in it that was stopping it in one loop
Been reading up and there not much about using it in a for loop
 
Mike I'm using mplab X v3.65 and the watch variables but it only updates if I stop it.
 
I no about the for ( ; ; ) loop what I couldn't find is how return is working there nothing really about it in any thing I found on the xc8 nothing showing it used with a for loop .
 
What's happening is like you said the code runs to the return and the pic reboots cause as soon as it hits it the messes up the LCD
I guess it's a poor way to restart main.
But I don't no enough about xc8 LOL
 
In a if statement return a value but in the for loop it's just a loop so I couldn't figure why a return was being used.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…