R
R
RoR12122020-10-15 13:11:50
Java
RoR1212, 2020-10-15 13:11:50

Why does Java have labels but no goto statement?

Why does Java have labels but no goto statement? Why is it bad manners to use the goto statement, but labels are fine?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan, 2020-10-15
@RoR1212

The goto statement can jump to any point in the program, while the break statement is your_label; can be used to quickly exit two or more cycles. It is because of this that you can use a label with a break statement in cycles, and not everywhere, unlike goto. As far as I know, using a label is not a good practice in Java, and most likely the code can be refactored so that you don't have a bunch of nested loops.

J
Jacen11, 2020-10-15
@Jacen11

There is nothing wrong with labels either. Do not use all of this simply because it is unrealistic to figure out how the code works with them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question