1. Looping through array.

How can I get it to loop through an array until it reaches the value of -1? Can I do while(i!=-1)? I think a for statement afterwards but what do I put in the middle? for(j=0,?,j++)?

Dont know if that will work. The only thing I can pass to this function is the array itself. So I cant do a counter of the number of user inputs.

2. What range of numbers does your array contain? Does it accend or decend from -1 to something, or is it random numbers that contain -1?

3. if i understand u better if u want to check for -1; it means that u printing the array in a revese order. u point the pointer at the end of anj array. and u loop back to the first elements. so your while look show be
Code:
```#define MAX 10
.
.

int i=MAX;
int array[MAX] = {10,20,30,40,50};
.
.
while(i>-1)
printf("%d\t",array[i]);

// with the for loop it same again

for(j=MAX;j>-1;j++)
printf("%d\t",array[i]);

or if u wanted to print it asusual from the 0th element
for(i=0;i<MAX;i++)
printf("%d\t",array[i]);```
note that all array elements starts from 0(array[0],[1][2]...)

it would be better if u could show us your code attempt

ssharish2005

4. What they mean is this:
Code:
```int array[] = { 1, 4, 77, 2, 9, 123, -1 };
int x;

for( x = 0; array[ x ] != -1; x++ )
...do something...```
They posted a "do my homework for me!!!!OMGOMG!!" earlier that got deleted. If it wasn't them, and I'm pretty sure it was, it's someone with the same homework problem. At any rate, simply compare the value in the array to -1, and stop when you reach it.

Quzah.

5. Originally Posted by quzah
What they mean is this:
Code:
```int array[] = { 1, 4, 77, 2, 9, 123, -1 };
int x;

for( x = 0; array[ x ] != -1; x++ )
...do something...```
They posted a "do my homework for me!!!!OMGOMG!!" earlier that got deleted. If it wasn't them, and I'm pretty sure it was, it's someone with the same homework problem. At any rate, simply compare the value in the array to -1, and stop when you reach it.

Quzah.

This is what I tried and it wont actually stop at the -1 but keeps on going. But for some reason at stops at 49 for the first set and at 74 for the second set.

this is what I tried, similar to what is shown above:

Code:
```int setCardinality(int a[]){

int i;
int numberElements=0;

for(i=0;a[i]!=-1;i++){
numberElements++;
printf("i is %d, numberElements is %d",i, numberElements); /*put in for test, and see that it is not stopping when -1 is hit*/
}
return (numberElements);

}```

6. > This is what I tried and it wont actually stop at the -1 but keeps on going
You also need to show the context in which it is being called then as well.