Code:#include<stdio.h> int main(){ int i=1; for(i=0;i=-1;i=1) { printf("%d ",i); if(i!=1) break; } return 0; }
The output for this is: -1. Can some explain to me why?
Code:#include<stdio.h> int main(){ int i=1; for(i=0;i=-1;i=1) { printf("%d ",i); if(i!=1) break; } return 0; }
The output for this is: -1. Can some explain to me why?
= is for assignment, == is for comparison. Now, think about the anatomy of a for loop:Code:for(i=0;i=-1;i=1) {
Every time through the loop, you have to check (execute) the loop condition to see whether you should keep looping or stop.Code:for (initial; loop condition; loop increment)
Thank you for your help