![]() |
VOOZH | about |
Most people, who have programmed in C programming language, are aware of goto and label statements which are used to jump from one point to another unlike Java, Dart also doesn't have any goto statements but indeed it has labels that can be used with continue and break statements and help them to take a bigger leap in the code.
Dart does allow line breaks between labels and loop control statements.
Example :
Output:
You are inside the loop GeekThe loop does not return because a break with a label exits the entire labeled loop rather than just the inner loop.
Example :
Output:
You are inside the loop Geek
You are inside the loop Geek
You are still inside the loop
The above code results in printing the statement twice because of the condition; it didn't break out of the loop and thus printed it twice.
Dart does not have a goto statement like C, but it does support labels for use with break and continue. These labels enable control to be transferred to specific loops, making it easier to exit nested loops or skip iterations efficiently.
By understanding how to use labels, you can effectively manage complex loops without unnecessary nesting or redundant conditions.