question

sachin T3 avatar image
0 Likes"
sachin T3 asked sachin T3 commented

Exit "for loop "

is there a command to exit the For Loop. I am running a code to check something and once found i dont want to continue with the loop, i want to break the look and get out of it to execute next statements. Can anyone suggest the command to get out of the For Loop.

FlexSim 21.2.1
for loop
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Jeanette F avatar image
1 Like"
Jeanette F answered sachin T3 commented

Hello @sachin T3,

You can use an if statement inside of your for loop to check that you found what you were looking for and then have have break written inside of that if statement. This will allow you to break from the loop.

 for (int i; i<5; i++){
      x+=1;
      if (x == 3){
          break;
      }
 }
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

sachin T3 avatar image sachin T3 commented ·

Thank you Jeanette!


0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.