+ 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.

14th Jul 2017, 10:51 AM
Bharath kumar
Bharath kumar - avatar
3 odpowiedzi
+ 2
u can use labels..
14th Jul 2017, 10:56 AM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 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; } } }
14th Jul 2017, 11:11 AM
Boris Batinkov
Boris Batinkov - avatar