how to run the index with 1, 2, 2,3,4,5..... in an array from a do loop

P

Peter Pichler

OZ said:
how to run the index with 1, 2, 2,3,4,5..... in an array from a do loop ?

I am not sure I understand your question. Is this what you want?

int index = 1;
do {
run_the_index(index);
if (index == 2)
run_the_index(index);
++index;
} while (1);
 
M

Mark McIntyre

how to run the index with 1, 2, 2,3,4,5..... in an array from a do loop ?

you need to explain more clearly.
Do you mean you want to create arrays that start from 1? if so, just
dont do it. C programmers know that arrays start from 0, if you try to
use 1-based arrays you'll become a bad programmer and write confusing
code.

Do you literally mean you want to loop from 1 to 5 in the array? If
so, use an index variable
int i =1;
do{
somethingwith(array[i++]);
while(i<6);
 
C

CBFalconer

OZ said:
how to run the index with 1, 2, 2,3,4,5.....
in an array from a do loop ?

A magnificently clear exposition of the problem </sarcasm>

Making heroic assumptions about what OZ wants to do, try:

i = 0;
do {
accessarraywith[i + (i < 2)];
while (someterminationvalue > ++i);
 
D

Derk Gwen

# how to run the index with 1, 2, 2,3,4,5..... in an array from a do loop ?

for (i=1; i<=n; i++) {loop statements}
 
D

Dan Henry

# how to run the index with 1, 2, 2,3,4,5..... in an array from a do loop ?

for (i=1; i<=n; i++) {loop statements}

With that recommendation, might the 'gotcha' be the "2, 2," in "1, 2,
2,3,4,5....."?
 
P

Peter Nilsson

OZ said:
how to run the index with 1, 2, 2,3,4,5..... in an array from a do loop ?

int i = 1, j = 0;

do
{
...
if (i == 2 && ++j < 2) i--; /* repeat 2 twice */
i++;
}
while (...);
 
M

Martin Ambuhl

Derk said:
# how to run the index with 1, 2, 2,3,4,5..... in an array from a do loop ?

for (i=1; i<=n; i++) {loop statements}

That doesn't repeat the value 2 for i, now does it?
 
A

August Derleth

Martin said:
That doesn't repeat the value 2 for i, now does it?

It doesn't replicate the typo, no.

(Was that a typo? Or is the OP just trying to do something really odd?
The post isn't clear.)

So, assuming the OP wasn't mistaken in his post, I'll make an attempt:

/* An enclosing translation unit */
i = 1;
/* use i at 1 */
i = 2;
/* use i at 2 */
/* use it again, for whatever reason... */
for (i = 3; ; i++) { /* assuming an inifinte loop here */
/* use i at 3, 4, 5, ... */
}
/* finish translation unit */

There. That code is bug-for-bug compatible with the woefully inadequate
specification. ;) I don't vouch for its efficiency, but I do believe it
to be correct (or as correct as the specification is). I hope the OP can
make some use out of it.
 

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

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top