# loops

• 03-24-2007
crvenkapa
loops
can some how this part of code to be replaced with a loop(for or while)
Code:

```if(x==2) a[0]=(soberi(a[0],a[1])); if(x==3){ a[0]=(soberi(a[0],a[1])); a[0]=(soberi(a[0],a[1])); a[0]=(soberi(a[0],a[2])); a[0]=(soberi(a[0],a[3])); a[0]=(soberi(a[0],a[4])); } if(x==6) { a[0]=(soberi(a[0],a[1])); a[0]=(soberi(a[0],a[2])); a[0]=(soberi(a[0],a[3])); a[0]=(soberi(a[0],a[4])); a[0]=(soberi(a[0],a[5])); } if(x==7) { a[0]=(soberi(a[0],a[1])); a[0]=(soberi(a[0],a[2])); a[0]=(soberi(a[0],a[3])); a[0]=(soberi(a[0],a[4])); a[0]=(soberi(a[0],a[5])); a[0]=(soberi(a[0],a[6])); } if(x==8) { a[0]=(soberi(a[0],a[1])); a[0]=(soberi(a[0],a[2])); a[0]=(soberi(a[0],a[3])); a[0]=(soberi(a[0],a[4])); a[0]=(soberi(a[0],a[5])); a[0]=(soberi(a[0],a[6])); a[0]=(soberi(a[0],a[7])); } if(x==9) { a[0]=(soberi(a[0],a[1])); a[0]=(soberi(a[0],a[2])); a[0]=(soberi(a[0],a[3])); a[0]=(soberi(a[0],a[4])); a[0]=(soberi(a[0],a[5])); a[0]=(soberi(a[0],a[6])); a[0]=(soberi(a[0],a[7])); a[0]=(soberi(a[0],a[8])); } if(x==10) { a[0]=(soberi(a[0],a[1])); a[0]=(soberi(a[0],a[2])); a[0]=(soberi(a[0],a[3])); a[0]=(soberi(a[0],a[4])); a[0]=(soberi(a[0],a[5])); a[0]=(soberi(a[0],a[6])); a[0]=(soberi(a[0],a[7])); a[0]=(soberi(a[0],a[8])); a[0]=(soberi(a[0],a[9]));```
• 03-24-2007
Salem
Something involving
while ( i < x )
perhaps?

Or
for ( i = 0 ; i < x ; i++ )
• 03-24-2007
crvenkapa
yes how to use for and while but i have problem to
rest of the code i dont now what to write after for
• 03-24-2007
crvenkapa
• 03-24-2007
Salem
Dunno - maybe replace
a[0]=(soberi(a[0],a[1]));
with
a[0]=(soberi(a[0],a[i]));

Why are you assigning to the same location each time?
• 03-24-2007
crvenkapa
i dont now other way
• 03-24-2007
crvenkapa
is this code is going to be same like that above
Code:

```for(i=0;i<x;i++) a[0]=(soberi(a[0],a[i]));```
• 03-24-2007
Salem
More or less.

Though it seems you should start at 1, not 0

Also, your cases 2 and 3 don't seem to fit the pattern that the rest of them follow - is that just a typo on your part?
• 03-24-2007
crvenkapa
yes it's mistake in typing it's should be
Code:

```if(x==3){ a[0]=(soberi(a[0],a[1])); a[0]=(soberi(a[0],a[2])); } if(x==4) { a[0]=(soberi(a[0],a[1])); a[0]=(soberi(a[0],a[2])); a[0]=(soberi(a[0],a[3])); } if(x==5) { a[0]=(soberi(a[0],a[1])); a[0]=(soberi(a[0],a[2])); a[0]=(soberi(a[0],a[3])); a[0]=(soberi(a[0],a[4])); }```