Why I Should/n't Use goto ?

Revision en2, by Halit, 2020-05-25 17:24:45

Hi!

I learnt goto keyword in C++. But I couldn't see any code with using goto. So Why I shouldn't use goto? I want to use for this situation:

for(int i = 1;i <= n;i++){
   for(int j = 1;j <= n;j++){
       //some codes
       if(break all fors)
         goto q;
       //some codes
   }
}
q:

When I don't know goto keyword I am doing like this:

for(int i = 1;i <= n;i++){
   bool br = false;
   for(int j = 1;j <= n;j++){
       //some codes
       if(break all fors){
         br = true;
         break;
       }
       //some codes
   }
   if(br)
      break;
}

It's easy to see second code is longer.So why anyone doesn't use goto keyword?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Halit 2020-05-25 17:24:45 42
en1 English Halit 2020-05-25 17:21:08 688 Initial revision (published)