শনিবার, ৩০ মে, ২০১৫

1. If loop body contain only one statement then brace is optional. For example:

(a)
#include<stdio.h>
int main(){
    int i,j=0;
   
    for(i=0;i<=3;++i,i++,++j )
         printf("%d %d ",i,j);
    }

return 0;        
}

Output: 0 0 2 1

(b)
#include<stdio.h>
int main(){
    int x,y=5;
       for(x=0;x<3;x++)
         if(y>=5)
             printf(" %d",x);
return 0;        
}

Output: 0 1 2

2. Loop without body is possible. For example

#include<stdio.h>
int main(){
    int i;
   
    for(i=0;i<=10;i++);
    printf("%d",i);
   
return 0;        
}

Output: 11
3. Braces of loop body behave as block. For example

#include<stdio.h>
int main(){
    int i;
   
    for(i=0;i<=2;i++){
         int i=8;
         printf("%d ",i);

    }
    printf("%d",i);
   
return 0;        
}

Output: 8 8 8 3