# need while(for(loop)) to be condition

• 10-12-2006
thestien
need while(for(loop)) to be condition
hi im writing a program that need the condition of the do... while loop to be a for loop.
well at least thats what i think i need .
the format is i have a class and made an array of objects(h[])
Code:

```do { for (i=0;i<total;i++) {     while (h[i].product<AccumNum)     {               h[i].num1++;                 h[i].product=num1*num2;                 AccumNum=AccumNum+h[i].num1;       }//first while brace }//for brace }//do brace     while (for (i=0;i<total;1++){h[i].product<AccumNum;})```
the array size of h is user defined in an int named total.
the members of the class are float num1, num2 and sum
is it possible to use a for loop as the while loops condition
edit... sorry i forgot to say the perpouse of these loop is to check that all product=more than the total accumnum
so if i have 3 sums
say product 1 is 3*4=12
product2 is 6*4=24
product 3 is 7*4=28
so if accum number was made to 12 then it would all be valid
but if accum number was say 30 then none would be valid so it would have to loop again
making product1 3*5
product2 6*5
product3 7*5
my example sum are not true to a proper value but thats the idea of the loop
• 10-12-2006
thestien
sorry if this is bumping but i felt it needed another post
the do... while loop is intended to use the bottom while as the while part of that loop.
if it doesnt could you please tell me a way in which it would thank you in advance.
• 10-12-2006
CornedBee
You'd have to write a function containing the for loop and returning false if any comparison fails, but this still looks bad to me. And inefficient. Don't forget inefficient.

Oh, and if h starts out with any element smaller than AccumSum, the loop will probably go on until AccumSum overflows. (Not entirely sure about the numeric relationships between sum and AccumNum.) The whole thing is completely broken.

What is AccumSum supposed to be? Because right now it's nonsensical.
Also nonsensical is the name of the sum member, because sum is usually the result of an addition, but you put the result of a multiplication in it, which is usually called product.
• 10-12-2006
thestien
i have every thing written on paper in pusedo codeish
ok the funtion would be something like this maybe?
Code:

```bool somefn(i have no idea what goes in here) { for (i=0;i<total;i++) if  (h[i].product<AccumNum) { return false}```
im not very good at c++ yet but im trying to learn so please be patient with me if i make no sense :) thank you
also if this type of function would work how would i impliment it into the do while loop i made?

i know the code may seem inefficient but i wrote it before without classes or anything like that so now im trying to rewrite it in a different way
• 10-12-2006
thestien
ok i cant for the life of me make a function i dont know why but every time i do and try to put it into my it brings back some kind of error or another could sombody please tell me how to do
a. define and write the function
b. where t oput it into my program.

if i put it before main it doesnt compile because the h[] hasnt been set up yet
and if i put it after h[] has been set up i still get errors ive tried so many things that i forgot which error came from what i used do i thought the best way to get this to work would to be if you could point me in the right direction. i have read tutorials on functions but because my function will need to use and array of objects i cant quite figure out how to do it
thank you in advance