Results 1 to 7 of 7

Thread: Simple for loop

  1. #1
    Junior Member
    Join Date
    Apr 2008
    Answers
    1

    Simple for loop

    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?


  2. #2
    Junior Member
    Join Date
    Apr 2008
    Answers
    1

    Re: Simple for loop

    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);
     }
    }



  3. #3

    Re: Simple for loop

    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


  4. #4
    Junior Member
    Join Date
    Nov 2007
    Answers
    1

    Re: Simple for loop

    Quote Originally Posted by jbmukund View Post
    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?
    I have a doubt as to whether more than one condition can be tested in for loop....


  5. #5
    Junior Member
    Join Date
    May 2008
    Answers
    1

    Re: Simple for loop

    yes!! you can test more than one condition in for loops


  6. #6
    Junior Member
    Join Date
    May 2008
    Answers
    2

    Re: Simple for loop

    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.


  7. #7
    Junior Member
    Join Date
    Nov 2008
    Answers
    2

    Smile Re: Simple for loop

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact