01 | local children = script.Parent.Parent:GetChildren() |
02 | for i = 1 , #children do |
03 | if children [ i ] :IsA( "BasePart" ) then |
04 |
05 | -----should a break go here------- |
06 | print ( "script ran" ) |
07 | -----or here?--------- |
08 |
09 | end |
10 | end |
I want the loop to break when children[i] is a basepart.
for the code under the for loop and the if statement, were is the best place to put a break.
Now that I understand the question, break goes after any code you want to run. Code executes top to bottom, so generally put break after any code you want to run.
1 | local children = script.Parent.Parent:GetChildren() |
2 | for i = 1 , #children do |
3 | if children [ i ] :IsA( "BasePart" ) then |
4 | print ( "script ran" ) |
5 | break --here |
6 | end |
7 | end |
If you put break before the print, it would exit the loop first, so nothing would be printed.