Hi guys,
main()
{
int i=0, j=0,z=0;
For(i=0; j,z;i++)
printf("i = %d\n",i);
}
what does this mean?????
how does the condition j,z get evaluated?
Printable View
Hi guys,
main()
{
int i=0, j=0,z=0;
For(i=0; j,z;i++)
printf("i = %d\n",i);
}
what does this mean?????
how does the condition j,z get evaluated?
Not at all.
Your snipplet does nothing.
If you set j and z to true, you have an endless loop.
here a for how it's used normally
[CODE]
main() {
int i=0;
for(i=0;i<11;i++) {
printf("i = %d\n",i);
}
}
[/CODE]
Hello,
your for loop will do nothing. bcz, it will check the value of j and if it is non zero ,it will execute the printf(). Here it is zero , so wont do anything
[QUOTE=jbmukund;28765]Hi guys,
main()
{
int i=0, j=0,z=0;
For(i=0; j,z;i++)
printf("i = %d\n",i);
}
what does this mean?????
how does the condition j,z get evaluated?[/QUOTE]
I have a doubt as to whether more than one condition can be tested in for loop....
yes!! you can test more than one condition in for loops
in for loop we can go for multiple condition.
your for loop , i.e. syntactically correct , but you'll not get any output, due to condition always 0 , means false . so won't execute next statement.
in the for loop of the code
main(){
int i=0,j=0,z=0;
for(i=0;j,z;i++)
printf("%d",i);
}
here the variables j=0,z=0;
In the conditional part of for loop,there is a comma(,) operator which which evaluates expression from left-->right.It always considers the rightmost value.
So,the fate of loop doesn't depend on value of j.But it depends on the value of Z.
If Z has a nonzero value,then the loop will execute infinitely.
If Z has a Zero value,the loop will not be executed as conditional part is calculated as false.