for loop increment condition ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kenneth6
    New Member
    • Mar 2007
    • 79

    #1

    for loop increment condition ?

    Code:
    class* object;
    
    int num=7-object->getNum();
    for(int i=0; i<num; i++)
    { ...... }
    
    for(int i=0; i<7-object->getNum(); i++) 
    [U]OR[/U] 
    for(int i=0; i<(7-object->getNum()); i++)
    { ...... }
    Are there any difference from the above two sets of codes?

    I cannot get the expected output from the second set. what is the reason for that?
  • Savage
    Recognized Expert Top Contributor
    • Feb 2007
    • 1759

    #2
    Originally posted by kenneth6
    Code:
    class* object;
    
    int num=7-object->getNum();
    for(int i=0; i<num; i++)
    { ...... }
    
    for(int i=0; i<7-object->getNum(); i++) 
    [U]OR[/U] 
    for(int i=0; i<(7-object->getNum()); i++)
    { ...... }
    Are there any difference from the above two sets of codes?

    I cannot get the expected output from the second set. what is the reason for that?
    Are you decrementing number that is returned with getNum()?
    If so there is the difference,if not those for statements are equal.

    Comment

    • kenneth6
      New Member
      • Mar 2007
      • 79

      #3
      Originally posted by Savage
      Are you decrementing number that is returned with getNum()?
      If so there is the difference,if not those for statements are equal.

      what do you mean by "decrementi ng number"?? the num returned from function is constant for each time.

      Comment

      • Savage
        Recognized Expert Top Contributor
        • Feb 2007
        • 1759

        #4
        Originally posted by kenneth6
        what do you mean by "decrementi ng number"?? the num returned from function is constant for each time.
        Then it should give you the same output.Can we see what are you doing in for loops?

        Comment

        Working...