+ 8
Can we use goto keyword in java? If not, What are the other keywords that can be used for similar functionality?
If possible, Write a program using goto Keyword.
3 Answers
+ 2
u can use labels..
+ 1
You can use labels, but it is not a very good practice in some cases.
Example (Break from all by innermost loop):
FIRST:
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 10; j++) {
for (int k = 0; k < 15; k++) {
System.out.printf("%d, %d, %d%n", i, j, k);
if (i == 2) break FIRST;
}
}
}