multiple updates in for statement

Discussion in 'C++' started by Michael, May 21, 2004.

  1. Michael

    Michael Guest

    Ok how do i implement:

    #define MYCONST 10

    for(int i=0;i<MYCONST;i++,j--)
    {
    }

    that is I want two items in the last part of the for statement.
    Thanks
    Mike
     
    Michael, May 21, 2004
    #1
    1. Advertising

  2. "Michael" <> wrote in message
    news:c8l58l$3n2$...
    > Ok how do i implement:
    >
    > #define MYCONST 10
    >
    > for(int i=0;i<MYCONST;i++,j--)
    > {
    > }
    >
    > that is I want two items in the last part of the for statement.
    > Thanks
    > Mike
    >


    I don't see anything wrong with what you've posted. What happens when you
    compile/run it?

    john
     
    John Harrison, May 21, 2004
    #2
    1. Advertising

  3. Michael wrote:

    > Ok how do i implement:
    >
    > #define MYCONST 10
    >
    > for(int i=0;i<MYCONST;i++,j--)
    > {
    > }


    Your implementation is right.
    I do not understand what are you asking...

    - Dario
     
    =?UTF-8?B?IkRhcmlvIChkcmlua2luZyBjb++sgGVlIGluIHRo, May 21, 2004
    #3
  4. Michael

    Jeff Flinn Guest

    "Michael" <> wrote in message
    news:c8l58l$3n2$...
    > Ok how do i implement:
    >
    > #define MYCONST 10
    >
    > for(int i=0;i<MYCONST;i++,j--)
    > {
    > }
    >
    > that is I want two items in the last part of the for statement.


    Assuming j is defined somewhere, you're fine as is. If not how about:

    for( int i = 0, j = MYCONST ; i != MYCONST ; ++i, --j )
    {
    }

    Jeff F
     
    Jeff Flinn, May 21, 2004
    #4
  5. Michael

    Bill Seurer Guest

    Michael wrote:

    > Ok how do i implement:
    >
    > #define MYCONST 10
    >
    > for(int i=0;i<MYCONST;i++,j--)
    > {
    > }
    >
    > that is I want two items in the last part of the for statement.


    Is the problem you forgot to declare and initialize "j"?


    #define MYCONST 10

    int j = ???;

    for(int i=0;i<MYCONST;i++,j--)
    {
    }
     
    Bill Seurer, May 21, 2004
    #5
  6. In message <c8le09$1av2$>, Bill Seurer
    <> writes
    >Michael wrote:
    >
    >> Ok how do i implement:
    >> #define MYCONST 10
    >> for(int i=0;i<MYCONST;i++,j--)
    >> {
    >> }
    >> that is I want two items in the last part of the for statement.

    >
    >Is the problem you forgot to declare and initialize "j"?


    No (well, maybe), but as posted there's a missing comma between i++ and
    j--.


    --
    Richard Herring
     
    Richard Herring, May 27, 2004
    #6
  7. Richard Herring wrote:
    > In message <c8le09$1av2$>, Bill Seurer
    > <> writes
    >
    >> Michael wrote:
    >>
    >>> Ok how do i implement:
    >>> #define MYCONST 10
    >>> for(int i=0;i<MYCONST;i++,j--)
    >>> {
    >>> }
    >>> that is I want two items in the last part of the for statement.

    >>
    >>
    >> Is the problem you forgot to declare and initialize "j"?

    >
    >
    > No (well, maybe), but as posted there's a missing comma between i++ and
    > j--.


    Huh?
     
    Victor Bazarov, May 27, 2004
    #7
  8. Michael

    Jeff Schwab Guest

    Richard Herring wrote:
    > In message <c8le09$1av2$>, Bill Seurer
    > <> writes
    >
    >> Michael wrote:
    >>
    >>> Ok how do i implement:
    >>> #define MYCONST 10
    >>> for(int i=0;i<MYCONST;i++,j--)
    >>> {
    >>> }
    >>> that is I want two items in the last part of the for statement.

    >>
    >>
    >> Is the problem you forgot to declare and initialize "j"?

    >
    >
    > No (well, maybe), but as posted there's a missing comma between i++ and
    > j--.


    Eh... Huh? Do you think there are supposed to be two commas?
     
    Jeff Schwab, May 27, 2004
    #8
  9. In message <Jmotc.672$>, Victor Bazarov
    <> writes
    >Richard Herring wrote:
    >> In message <c8le09$1av2$>, Bill Seurer
    >><> writes
    >>
    >>> Michael wrote:
    >>>
    >>>> Ok how do i implement:
    >>>> #define MYCONST 10
    >>>> for(int i=0;i<MYCONST;i++,j--)
    >>>> {
    >>>> }
    >>>> that is I want two items in the last part of the for statement.
    >>>
    >>>
    >>> Is the problem you forgot to declare and initialize "j"?

    >> No (well, maybe), but as posted there's a missing comma between i++
    >>and j--.

    >
    >Huh?


    Sorry, I take it back. This stupid sans-serif font runs the comma
    indistinguishably into the j :-(

    --
    Richard Herring
     
    Richard Herring, May 27, 2004
    #9
  10. In message <>, Jeff Schwab
    <> writes
    >Richard Herring wrote:
    >> In message <c8le09$1av2$>, Bill Seurer
    >><> writes
    >>
    >>> Michael wrote:
    >>>
    >>>> Ok how do i implement:
    >>>> #define MYCONST 10
    >>>> for(int i=0;i<MYCONST;i++,j--)
    >>>> {
    >>>> }
    >>>> that is I want two items in the last part of the for statement.
    >>>
    >>>
    >>> Is the problem you forgot to declare and initialize "j"?

    >> No (well, maybe), but as posted there's a missing comma between i++
    >>and j--.

    >
    >Eh... Huh? Do you think there are supposed to be two commas?


    See my reply to VB :-(

    --
    Richard Herring
     
    Richard Herring, May 27, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gary
    Replies:
    7
    Views:
    4,881
    Joe Smith
    Jan 20, 2004
  2. Replies:
    3
    Views:
    807
  3. Jay McGavren
    Replies:
    11
    Views:
    1,142
    Alan Krueger
    Jan 16, 2006
  4. problems with SELECT statement for updates

    , Apr 10, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    118
  5. John T.
    Replies:
    5
    Views:
    142
    Eric Hodel
    Jun 5, 2008
Loading...

Share This Page