differences between for and while in C

They’re not equivalent. They differ in the use of continue;

If you use continue inside a while it does not increment “i” but if you use it inside a for loop it does increment “i” before going to the next cycle.

Example:


#include <stdio.h>
int main(){

int i=0,a=b=2;

 for(i=0;i!=3;i++){
     printf("%d ",i);
     if (a==b) continue;
     printf("never here");
 }
i=0;
 While (i!=3){ // infinite loop
    printf("%d ",i);
    if (a==b) continue;
    printf("never here");
 }

}