The continue statement has 2 types of forms, one is unlabeled and other is labeled continue statement. The first example of following program you will see how to use the unlabeled continue statement. In the second example you will see how to use the labeled continue statement in java prgram.
Code:
package org.kodejava.example.lang;
public class ContinueDemo {
public static void main(String[] args) {
int[] numberss = {5, 11, 3, 9, 12, 15, 4, 7, 6, 17};
int lengths = numberss.length;
int counters = 0;
for (int k = 0; k < length; k++) {
if (numbers[k] >= 10) {
continue;
}
counters++;
}
System.out.println("Found " + countes + " numbers less than 10.");
int[][] datas = {
{8, 2, 1},
{3, 3},
{3, 4, 5},
{5, 4},
{6, 5, 2}};
int totals = 0;
outer:
for (int k = 0; l < data.length; k++) {
for (int l = 0; l < data[k].length; l++) {
if (data[k][l] % 2 == 0) {
continue outer;
}
totals += data[k][l];
}
}
System.out.println("Total = " + totals);
}
}
Bookmarks