Connecting Tech Pros Worldwide Help | Site Map

multiple updates in for statement

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 11:24 AM
Michael
Guest
 
Posts: n/a
Default multiple updates in for statement

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



  #2  
Old July 22nd, 2005, 11:24 AM
John Harrison
Guest
 
Posts: n/a
Default 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


  #3  
Old July 22nd, 2005, 11:24 AM
Dario (drinking coffee in the office…)
Guest
 
Posts: n/a
Default 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
  #4  
Old July 22nd, 2005, 11:24 AM
Jeff Flinn
Guest
 
Posts: n/a
Default 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


  #5  
Old July 22nd, 2005, 11:24 AM
Bill Seurer
Guest
 
Posts: n/a
Default 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--)
{
}
  #6  
Old July 22nd, 2005, 11:34 AM
Richard Herring
Guest
 
Posts: n/a
Default 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
  #7  
Old July 22nd, 2005, 11:34 AM
Victor Bazarov
Guest
 
Posts: n/a
Default 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?
  #8  
Old July 22nd, 2005, 11:34 AM
Jeff Schwab
Guest
 
Posts: n/a
Default 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?
  #9  
Old July 22nd, 2005, 11:34 AM
Richard Herring
Guest
 
Posts: n/a
Default 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
  #10  
Old July 22nd, 2005, 11:35 AM
Richard Herring
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.