breaking loops

+2 Vaggelis Dou · November 21, 2015
how can i stop a loop but without break ?

Post a Reply

Replies

Oldest  Newest  Rating
+1 c student · November 21, 2015
make the condition not satisfied
+1 Vaggelis Dou · November 21, 2015
something else?
+1 c student · November 21, 2015
there is another way, but why do require such a method?
+1 Vaggelis Dou · November 21, 2015
what way?
+1 Eryk Humberto Oliveira Alves · November 21, 2015
I don't understand why you don't want to use break; It's awesome!


The only two ways I know is (1) making the condition not satisfied, as the C Student said, and using break;

Last week I created a program which I had to break a loop. The code is:

for ( i = 0 ; i < nAtendentes ; i++ )
                    if( atendenteEstado == 0 ){
                        atendente = i+1;
                        break;
                    }

The break; breaks the for loop. 
I could have also written like:

for ( i = 0 ; i < nAtendentes ; i++ )
                    if( atendenteEstado == 0 ){
                        atendente = i+1;
                        i = nAtendentes;
                    }

If that doesn't help you, please inform me your situation, so I can help you better.
+1 Vaggelis Dou · November 22, 2015
i like break too but i just ask if there is and another faster way. thanks
+1 c student · November 22, 2015
what do you mean "faster"?  if you meant optimizing your code, you can use the -O flag with gcc (assuming you're using code blocks with mingw) or write your program in assembly.
+1 Vaggelis Dou · November 22, 2015
Thanks
  • 1

C

107,322 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator