Connecting Tech Pros Worldwide Help | Site Map

multiple updates in for statement

Michael
Guest
 
Posts: n/a
#1: Jul 22 '05
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


John Harrison
Guest
 
Posts: n/a
#2: Jul 22 '05

re: multiple updates in for statement



"Michael" <slick_mick_00@hotmail.com> wrote in message
news:c8l58l$3n2$1@hercules.btinternet.com...[color=blue]
> 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
>[/color]

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

john


Dario (drinking coffee in the office…)
Guest
 
Posts: n/a
#3: Jul 22 '05

re: multiple updates in for statement


Michael wrote:
[color=blue]
> Ok how do i implement:
>
> #define MYCONST 10
>
> for(int i=0;i<MYCONST;i++,j--)
> {
> }[/color]

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

- Dario
Jeff Flinn
Guest
 
Posts: n/a
#4: Jul 22 '05

re: multiple updates in for statement



"Michael" <slick_mick_00@hotmail.com> wrote in message
news:c8l58l$3n2$1@hercules.btinternet.com...[color=blue]
> 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.[/color]

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


Bill Seurer
Guest
 
Posts: n/a
#5: Jul 22 '05

re: multiple updates in for statement


Michael wrote:
[color=blue]
> 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.[/color]

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


#define MYCONST 10

int j = ???;

for(int i=0;i<MYCONST;i++,j--)
{
}
Richard Herring
Guest
 
Posts: n/a
#6: Jul 22 '05

re: multiple updates in for statement


In message <c8le09$1av2$1@news.rchland.ibm.com>, Bill Seurer
<seurer@us.ibm.com> writes[color=blue]
>Michael wrote:
>[color=green]
>> 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.[/color]
>
>Is the problem you forgot to declare and initialize "j"?[/color]

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


--
Richard Herring
Victor Bazarov
Guest
 
Posts: n/a
#7: Jul 22 '05

re: multiple updates in for statement


Richard Herring wrote:[color=blue]
> In message <c8le09$1av2$1@news.rchland.ibm.com>, Bill Seurer
> <seurer@us.ibm.com> writes
>[color=green]
>> Michael wrote:
>>[color=darkred]
>>> 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.[/color]
>>
>>
>> Is the problem you forgot to declare and initialize "j"?[/color]
>
>
> No (well, maybe), but as posted there's a missing comma between i++ and
> j--.[/color]

Huh?
Jeff Schwab
Guest
 
Posts: n/a
#8: Jul 22 '05

re: multiple updates in for statement


Richard Herring wrote:[color=blue]
> In message <c8le09$1av2$1@news.rchland.ibm.com>, Bill Seurer
> <seurer@us.ibm.com> writes
>[color=green]
>> Michael wrote:
>>[color=darkred]
>>> 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.[/color]
>>
>>
>> Is the problem you forgot to declare and initialize "j"?[/color]
>
>
> No (well, maybe), but as posted there's a missing comma between i++ and
> j--.[/color]

Eh... Huh? Do you think there are supposed to be two commas?
Richard Herring
Guest
 
Posts: n/a
#9: Jul 22 '05

re: multiple updates in for statement


In message <u-2dnUyJ5qSjjivd4p2dnA@comcast.com>, Jeff Schwab
<jeffplus@comcast.net> writes[color=blue]
>Richard Herring wrote:[color=green]
>> In message <c8le09$1av2$1@news.rchland.ibm.com>, Bill Seurer
>><seurer@us.ibm.com> writes
>>[color=darkred]
>>> 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"?[/color]
>> No (well, maybe), but as posted there's a missing comma between i++
>>and j--.[/color]
>
>Eh... Huh? Do you think there are supposed to be two commas?[/color]

See my reply to VB :-(

--
Richard Herring
Richard Herring
Guest
 
Posts: n/a
#10: Jul 22 '05

re: multiple updates in for statement


In message <Jmotc.672$ri.59536@dfw-read.news.verio.net>, Victor Bazarov
<v.Abazarov@comAcast.net> writes[color=blue]
>Richard Herring wrote:[color=green]
>> In message <c8le09$1av2$1@news.rchland.ibm.com>, Bill Seurer
>><seurer@us.ibm.com> writes
>>[color=darkred]
>>> 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"?[/color]
>> No (well, maybe), but as posted there's a missing comma between i++
>>and j--.[/color]
>
>Huh?[/color]

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

--
Richard Herring
Closed Thread