multiple updates in for statement

M

Michael

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
 
J

John Harrison

Michael said:
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
 
G

Guest

Michael said:
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
 
J

Jeff Flinn

Michael said:
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
 
B

Bill Seurer

Michael said:
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--)
{
}
 
R

Richard Herring

Bill Seurer said:
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--.
 
J

Jeff Schwab

Richard said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top