Question

I'm a beginner in programming so I would like a simple answer :)

I have a for loop with multiple conditions, which prints out two arrays. It works, but i get a warning and a red line under for(). Why is it so and how can I avoid it? I'm writing it in C and I use a Geany compiler in Ubuntu. :)

for((i=LEN-1) && (j=1); (i>=LEN-3) && (j<=PODIUM); i-- && j++)  
{       
  printf("%d. koht: %s tulemusega %f\n", j, voist[i], tul[i]);      
}
Was it helpful?

Solution

for(i=LEN-1,j=1 ; (i>=LEN-3) && (j<=PODIUM); i--, j++) 

EDIT: It works because this is the correct syntax. you don't need to use and operator to combine two initializations or two increments. you can just use the ,

OTHER TIPS

This warning is because of the return value of (i=LEN-1) && (j=1) which is bot used further.To avoid the warning, try this

int temp;
... 

temp = (i=LEN-1) && (j=1);

for(; (i>=LEN-3) && (j<=PODIUM); i-- && j++)  
{  

     ....

     temp = (i=LEN-1) && (j=1);
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top