Next page | Contents page |

break & continue

break we saw as part of switch. It can also be used to break out of loops. Eg,


  for (i = 0; i < 100; i++)
  {
    if (i == j) break;
    // ...          //Only process up to j
  }

continue is used in loops to skip the rest of the current cycle and go to the next one. Eg,


  for (i = 0; i < 100; i++)
  {
    if (i % 3 != 0) continue;
    // ...      // only process multiples of 3
  }

It's rarely necessary to use either of these. Can you see how to modify the two examples on this page so that break and continue are not needed?

Next page | Contents page |