mardi 4 juillet 2017

if statement inside while that depends on the same variable that while depends on

consider the below programs. I would like to know why this codes behave in different way.Thankyou in advance.

this doesnot print any

#include<stdio.h>
int main() {
 int i=0;
 while(i<10)
  if(i<7)
   printf("value is%d",i++); 
}

while this does

 #include<stdio.h>
 int main() {
  int i=0;
  while(i<10)
   if(i<7)
    printf("value is%d\n",i++); 
 }

Aucun commentaire:

Enregistrer un commentaire