breaking out a loop

Here is my question, I want to test to see where names array is equal to a space " " an when the first space comes up I want to exit the whole thing. In short I want to get the subscript value of the first space in the array. how can I break from the if all the way outside of the for loop?

1
2
3
4
5
6
7
8
  for(int i=0; i<5; i++)
	{
		if(names[i]==" ")
		{
			elptr=i;
			break;
		}
	}
The for loop will only continue looping as long as it's second parameter is true (i<5); Make it false instead of using break.
i = 5;
Use a loop that's more appropriate for the purpose.

1
2
3
4
5
    int i=0;
    while (names[i] != ' ' )
        ++i ;

    // names[i] is ' '... 
Topic archived. No new replies allowed.