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?
This is a discussion on C programming (for loops) within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> int main(){ int i=1; for (i=0;i=-1;i=1) { printf( "%d " ,i); if (i!=1) break ; } return ...
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![]()