Connecting Tech Pros Worldwide Help | Site Map

multiple updates in for statement

  #1  
Old July 22nd, 2005, 12:24 PM
Michael
Guest
 
Posts: n/a
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, 12:24 PM
John Harrison
Guest
 
Posts: n/a

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, 12:24 PM
Dario (drinking coffee in the office…)
Guest
 
Posts: n/a

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, 12:24 PM
Jeff Flinn
Guest
 
Posts: n/a

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, 12:24 PM
Bill Seurer
Guest
 
Posts: n/a

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, 12:34 PM
Richard Herring
Guest
 
Posts: n/a

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, 12:34 PM
Victor Bazarov
Guest
 
Posts: n/a

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, 12:34 PM
Jeff Schwab
Guest
 
Posts: n/a

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, 12:34 PM
Richard Herring
Guest
 
Posts: n/a

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, 12:35 PM
Richard Herring
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Updates kadar2itse answers 1 February 7th, 2008 05:35 AM
Multiple column updates in a single query shorti answers 8 April 18th, 2007 04:25 AM
MyISAM engine: worst case scenario in case of crash (mysql, O/S,hardware, whatever) alf answers 110 December 9th, 2006 05:25 PM
Please Help With Complex Update Statement Logic pbd22 answers 22 November 13th, 2006 05:35 PM