Can my computer process 60,000 If statements?

Hello, in a part of my code, I am checking the length of strings. There are about 60,000 strings to be checked. If I change the number of strings to be checked to like 10, the code works fine. However, as I type this my compiler is still in"frozen" state. Is my PC in the process of evaluating the if statement.

Here is my if statement:
1
2
3
4
5
6
 for( abc = 0 ; abc < SizeOfList() ; abc ++){

                if( strlen ( Words[abc] ) == 9)
                    NineWordCounter++;
            }


Thank you for your time.
What do you mean by frozen state? Is the program running but just taking a long time? You shouldn't really be having any issues with looping through 60k elements.

Are you storing your strings in a C-style array? Or using a container?
If SizeOfList is the same function you have here http://www.cplusplus.com/forum/beginner/152067/ it's no wonder this is taking so long. Try something like this instead:

1
2
3
4
5
6
7
int abc_max = SizeOfList();

for( abc = 0 ; abc < abc_max ; abc ++) {

    if( strlen ( Words[abc] ) == 9)
        NineWordCounter++;
}
Last edited on
Thank you guys, more precisely, thank you m4ster r0shi! Your code worked out.

Thanks again!
Topic archived. No new replies allowed.