Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. for (i = 0; i < n; i++)
  2. {
  3.     for (j = 0; j < m; j++)
  4.     {
  5.         if (a[i] == b[j])
  6.         {
  7.             goto found;
  8.         }
  9.     }
  10.    
  11.     /* didnt find any common element */
  12. }
  13.  
  14. found:
  15.     /* got one: a[i] == b[i] */
  16.     ...
  17.    
  18.    
  19.  
  20. "Code involving a goto can always be written w/o one... the example above becomes..."
  21.  
  22. int found = 0;
  23.  
  24. for (i = 0; i < n && !found; i++)
  25. {
  26.     for (j = 0; j < m && !found; j++)
  27.     {
  28.         if (a[i] == b[j])
  29.         {
  30.             found = 1;
  31.         }
  32.     }
  33. }
  34.  
  35. if (found)
  36.     /* got one: a[i-1] == b[j-1] */
  37. ...
  38.  
  39. else
  40.     /* didnt find any common element */
  41. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement