# Thread: For loop doesn't work for positive integers -- while loop works fine.

1. ## For loop doesn't work for positive integers -- while loop works fine.

Code:
`#include<stdio.h>`
Code:
```#include<stdlib.h>

int sumFor(int daNumba);
int sumWhile(int daNumba);

/*      Main function           */

int main()
{
/*      Declare variables       */

int daNumba, startNumba, ansFor, ansWhile;

/*      Display welcome message         */

printf("\nWelcome to sumTimes2.\n");

/*      Message indicating what the program will do     */

printf("\nThis program will sum the integers between the one you enter and\n");
printf("the integer that is twice that value.\n");

scanf("%d", &daNumba);

/*      sumFor program      */

int sumFor(int daNumba)
{
int ansFor=0, startNumba=daNumba;
for( ; startNumba <= (daNumba*2); )
{
ansFor += startNumba++;
}
for( ; startNumba >= (daNumba*2); )
{
ansFor += startNumba--;
}
return ansFor;
}

/*      sumWhile program        */

int sumWhile(int daNumba)
{
int ansWhile=0, startNumba=daNumba;
while(daNumba >0 && startNumba <= (daNumba*2))
{
ansWhile += startNumba++;
}
while(daNumba <= 0 && startNumba >= (daNumba*2))
{
ansWhile += startNumba--;
}
return ansWhile;
}

/*      Display test statistics         */
printf("\nFor says the sum is %d\n", sumFor(daNumba));
printf("While says the sum is %d\n", sumWhile(daNumba));

/*      Display ending thank you message        */

printf("\nThank you for using sumTimes2. Bye!\n\n");

/*      Rieturn 0 for the compiler       */

return 0;

}
```

2. In sumFor, BOTH of the for loops run no matter what the input is, so you need some code logic which ensures only one runs - which one dependant on the sign of the input integer.