Skip to main content
Level 5
May 26, 2023
Répondu

Is There any Drawback to Using #break in a Script?

Hello,
Just curious if there's any drawbacks/issues with using #break in a script? For reference here is my script use case:

 

#foreach ($item in $customerProfilesList ) #if ( ( $item.age <=15 && $item.age >=13 ) && ( $item.membershipStatus.equals("Member") ) && ($item.financialEducationSOAREXPLORERGraduate.equals("0")) ) $item.fullName## #break #else Wings Member## #break #end #end

Basically I am looking to pull one name value (even if multiple records exist) since it's going within the same household and also to only pull one instance of the default if needed. Just curious if this has any potential ramifications? Testing-wise it seems to work correctly.

 

Ce sujet a été fermé aux réponses.
Meilleure réponse par Darshil_Shah1

AFAIK if the break statement meets your needs, I think you should be good with using it. However, IMO you might not want to overuse breaks in your code because they introduce more exit points. We generally want to keep exit points to a minimum since multiple exit points complicate logic and make it more difficult to comprehend code.

 

1 commentaire

Darshil_Shah1
Adobe Champion, Community Advisor, UG Leader
Adobe Champion, Community Advisor, UG Leader
May 26, 2023

AFAIK if the break statement meets your needs, I think you should be good with using it. However, IMO you might not want to overuse breaks in your code because they introduce more exit points. We generally want to keep exit points to a minimum since multiple exit points complicate logic and make it more difficult to comprehend code.