Conversation

Your input fuels progress! Share your tips or experiences on prioritizing mental wellness at work. Let's inspire change together!

Join the discussion and share your insights now!

Comments 0

Sharpen your coding skills—try JavaScript challenges on TOOLX now!

advertisement

Jump Statement in Dart Programming

jump statement in dart


Jump statements are used to jump from one statement to another statement, or it can be said that they transfer the execution to another statement from the current statement.

Types of jump statement

  • break
  • continue

a. break Statement

break statement in Dart inside any loop gives one way to break or terminate the execution of the loop containing it and hence, transfer the execution to the next statement following the loop. It is always used as the if-else construct.

void main()
{
var count = 0;
print("Dart break statement");
while(count <= 10){
 count++;
 if(count == 5){
  break;
  }
  print("Inside loop ${count}");
 }
print("Out of while loop");
}


After that if the statement has been used, in which a condition is given that if the count is equal to 5, it will break the execution and till then, it will print inside the loop statement. Once it has reached 5, it will print out of while loop statement.

b. Continue Statement

While the break is used to end the flow of control, continue on the other hand is used to continue the flow of control. When a continue statement is encountered in a loop, it does not terminate the loop but rather jumps the flow to the next iteration.

void main()
{
var num = 0;
print("Dart Continue Statement");
while(num<10){
num++;
 if(num == 5){
 print('5 is skipped');
 continue;
 }
 print("Number is ${num}");
}
print("Out of while loop");
}


After that, if the statement has to be used, in which a condition has been given that, if the count is equal to 5, it will skip the execution of the program. Next, the continue statement has been used. The continue statement will skip that line and execute the remaining code.


Dart jump statement break statement continue statement Dart programming

advertisement