Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > multiple updates in for statement

Reply
Thread Tools

multiple updates in for statement

 
 
Michael
Guest
Posts: n/a
 
      05-21-2004
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


 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      05-21-2004

"Michael" <(E-Mail Removed)> wrote in message
news:c8l58l$3n2$(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
=?UTF-8?B?IkRhcmlvIChkcmlua2luZyBjb++sgGVlIGluIHRoZSBv76yDY2XigKYpIg==?=
Guest
Posts: n/a
 
      05-21-2004
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
 
Reply With Quote
 
Jeff Flinn
Guest
Posts: n/a
 
      05-21-2004

"Michael" <(E-Mail Removed)> wrote in message
news:c8l58l$3n2$(E-Mail Removed)...
> 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


 
Reply With Quote
 
Bill Seurer
Guest
Posts: n/a
 
      05-21-2004
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--)
{
}
 
Reply With Quote
 
Richard Herring
Guest
Posts: n/a
 
      05-27-2004
In message <c8le09$1av2$(E-Mail Removed)>, Bill Seurer
<(E-Mail Removed)> 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
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      05-27-2004
Richard Herring wrote:
> In message <c8le09$1av2$(E-Mail Removed)>, Bill Seurer
> <(E-Mail Removed)> 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?
 
Reply With Quote
 
Jeff Schwab
Guest
Posts: n/a
 
      05-27-2004
Richard Herring wrote:
> In message <c8le09$1av2$(E-Mail Removed)>, Bill Seurer
> <(E-Mail Removed)> 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?
 
Reply With Quote
 
Richard Herring
Guest
Posts: n/a
 
      05-27-2004
In message <Jmotc.672$(E-Mail Removed)>, Victor Bazarov
<(E-Mail Removed)> writes
>Richard Herring wrote:
>> In message <c8le09$1av2$(E-Mail Removed)>, Bill Seurer
>><(E-Mail Removed)> 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
 
Reply With Quote
 
Richard Herring
Guest
Posts: n/a
 
      05-27-2004
In message <(E-Mail Removed)>, Jeff Schwab
<(E-Mail Removed)> writes
>Richard Herring wrote:
>> In message <c8le09$1av2$(E-Mail Removed)>, Bill Seurer
>><(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if statement that, when false, skips first statement in its block, executes second? Jay McGavren Java 11 01-16-2006 05:49 PM
How do I do a conditional statement in a constant statement? tkvhdl@gmail.com VHDL 3 12-16-2005 06:13 PM
Which of switch statement and if-else statement takes less time to execute? swaroophr@gmail.com C Programming 21 08-02-2005 09:24 AM
exec "statement" VS. exec "statement in globals(), locals() Ted Python 1 07-22-2004 08:51 AM
exec "statement" VS. exec "statement" in globals(), locals() tedsuzman Python 2 07-21-2004 08:41 PM



Advertisments