Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how to run the index with 1, 2, 2,3,4,5..... in an array from a do loop

Reply
Thread Tools

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

 
 
OZ
Guest
Posts: n/a
 
      02-07-2004
how to run the index with 1, 2, 2,3,4,5..... in an array from a do loop ?


TIA


 
Reply With Quote
 
 
 
 
Peter Pichler
Guest
Posts: n/a
 
      02-07-2004
"OZ" <> wrote in message
news:c03qq2$...
> 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);


 
Reply With Quote
 
 
 
 
Mark McIntyre
Guest
Posts: n/a
 
      02-08-2004
On Sun, 8 Feb 2004 07:05:00 +0800, in comp.lang.c , "OZ"
<> wrote:

>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);

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      02-08-2004
OZ wrote:
>
> 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);

--
Chuck F () ()
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


 
Reply With Quote
 
Derk Gwen
Guest
Posts: n/a
 
      02-08-2004
"OZ" <> wrote:
# 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}

--
Derk Gwen http://derkgwen.250free.com/html/index.html
Leave it to the Catholics to destroy existence.
 
Reply With Quote
 
Dan Henry
Guest
Posts: n/a
 
      02-08-2004
On Sun, 08 Feb 2004 01:15:59 -0000, Derk Gwen <>
wrote:

>"OZ" <> wrote:
># 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....."?

 
Reply With Quote
 
Peter Nilsson
Guest
Posts: n/a
 
      02-08-2004
"OZ" <> wrote in message
news:c03qq2$...
> 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 (...);

--
Peter


 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      02-08-2004
Derk Gwen wrote:

> "OZ" <> wrote:
> # 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?




--
Martin Ambuhl
 
Reply With Quote
 
August Derleth
Guest
Posts: n/a
 
      02-08-2004
Martin Ambuhl wrote:
> Derk Gwen wrote:
>
>> "OZ" <> wrote:
>> # 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?
>


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.

--
My address is yvoregnevna gjragl-guerr gjb-gubhfnaq guerr ng lnubb qbg pbz
Note: Rot13 and convert spelled-out numbers to numerical equivalents.


 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Making an array wrap, where last index + 1 = first index Shawn W_ Ruby 5 09-16-2009 02:45 PM
Array reference without index inside a for() loop -- help!! almurph@altavista.com C Programming 4 01-29-2009 03:53 PM
sorting index-15, index-9, index-110 "the human way"? Tomasz Chmielewski Perl Misc 4 03-04-2008 05:01 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57