{"id":12263,"date":"2022-01-27T18:28:23","date_gmt":"2022-01-27T18:28:23","guid":{"rendered":"https:\/\/www.directimpactsolutions.com\/?p=12263"},"modified":"2024-09-06T00:21:24","modified_gmt":"2024-09-06T00:21:24","slug":"single-pass-loop","status":"publish","type":"post","link":"https:\/\/www.directimpactsolutions.com\/en\/single-pass-loop\/","title":{"rendered":"Single-Pass Loop"},"content":{"rendered":"<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-1-1024x576.png\" alt=\"single-pass loop\" class=\"wp-image-12272\" style=\"width:667px;height:375px\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-1-1024x576.png 1024w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-1-300x169.png 300w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-1-768x432.png 768w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-1-600x338.png 600w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-1.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><p>This article explains the technique known as a single-pass loop, and why it is part of my script template. If you do a lot of error trapping or exception handling, this is a great technique to master.<\/p><p>The single-pass loop technique is inspired by the Try-Catch statement found in many programming languages. In a Try-Catch statement, the developer will put the happy path logic in the Try block, and if an exception happens, the code will jump into the Catch block to deal with the exception.<\/p><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"651\" height=\"199\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop.png\" alt=\"\" class=\"wp-image-12264\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop.png 651w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-300x92.png 300w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-600x183.png 600w\" sizes=\"auto, (max-width: 651px) 100vw, 651px\" \/><\/figure><p>Example Try-Catch Statement using JavaScript<\/p><p>The single-pass loop technique achieves this in FileMaker by using a loop. If everything goes well, the script will go down the list of script steps until it reaches the end of the loop, then jump out of the loop. The loop will cycle through one time at most, which is how this technique gets its name.<\/p><p>Then if something goes wrong and is captured by these Exit Loop If script steps, the script will jump out of the loop without executing the rest, and jump into the Catch block to handle this error.<\/p><figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1009\" height=\"330\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Achieving-Try-Catch-in-FM-using-Single-Pass-Loop.png\" alt=\"\" class=\"wp-image-12266\" style=\"width:851px;height:278px\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Achieving-Try-Catch-in-FM-using-Single-Pass-Loop.png 1009w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Achieving-Try-Catch-in-FM-using-Single-Pass-Loop-300x98.png 300w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Achieving-Try-Catch-in-FM-using-Single-Pass-Loop-768x251.png 768w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Achieving-Try-Catch-in-FM-using-Single-Pass-Loop-600x196.png 600w\" sizes=\"auto, (max-width: 1009px) 100vw, 1009px\" \/><\/figure><p>Try-Catch Statement in FileMaker<\/p><h3 class=\"wp-block-heading\">Single-Pass Loop vs. Exception Handling<\/h3><p>So what\u2019s the advantage of using a single pass loop over other exception handling methods?<\/p><p>Here\u2019s a comparison between the same script written in both methods.<\/p><figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"975\" height=\"1024\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/With-Single-Pass-Loop-2.png\" alt=\"\" class=\"wp-image-12268\" style=\"width:743px;height:780px\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/With-Single-Pass-Loop-2.png 975w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/With-Single-Pass-Loop-2-286x300.png 286w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/With-Single-Pass-Loop-2-768x807.png 768w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/With-Single-Pass-Loop-2-600x630.png 600w\" sizes=\"auto, (max-width: 975px) 100vw, 975px\" \/><\/figure><p>With a single-pass loop<\/p><figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"1016\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Without-Single-Pass-Loop-2.png\" alt=\"\" class=\"wp-image-12270\" style=\"width:741px;height:753px\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Without-Single-Pass-Loop-2.png 1000w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Without-Single-Pass-Loop-2-295x300.png 295w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Without-Single-Pass-Loop-2-768x780.png 768w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Without-Single-Pass-Loop-2-600x610.png 600w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure><p>Same logic, without a single-pass loop<\/p><p>In the two scripts above, I\u2019ve put a pin next to each script step that contributes to error handling. The one with a single-pass loop only has one script step per paragraph to capture the error and a centralized handling logic at the end. Whereas the one without a single-pass loop uses six script steps per paragraph to capture and handle errors.<\/p><h3 class=\"wp-block-heading\">Loop Advantages<\/h3><p>The former reads much better than the latter as the error handling script steps don\u2019t distract the reader from the actual business logic the script is trying to do. This makes the aforementioned loop a simple and elegant method to handle exceptions. It adds very little overhead on the developer, which will make it easier to adopt.<\/p><p>You can find out more about error handling in FileMaker check out our\u00a0<a href=\"https:\/\/youtu.be\/fc0I2HNi2nw\" target=\"_blank\" rel=\"noreferrer noopener\">video<\/a>\u00a0on this technique. For more information on this technique, feel free to <a href=\"http:\/\/directimpactsolutions.com\/en\/contact-us\/\">contact us<\/a>!<\/p><hr class=\"wp-block-separator has-alpha-channel-opacity\" style=\"margin-top:var(--wp--preset--spacing--70);margin-bottom:var(--wp--preset--spacing--70)\"\/><p class=\"has-small-font-size\"><em>*This article was originally written for AppWorks, which has since joined Direct Impact Solutions. This article is intended for informative purposes only. To the best of our knowledge, this information is accurate as of the date of publication.<\/em><\/p>","protected":false},"excerpt":{"rendered":"<p>This article explains the technique known as a single-pass loop, and why it is part of my script template. If you do a lot of error trapping or exception handling, this is a great technique to master. The single-pass loop technique is inspired by the Try-Catch statement found in many programming languages. In a Try-Catch &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/www.directimpactsolutions.com\/en\/single-pass-loop\/\"> <span class=\"screen-reader-text\">Single-Pass Loop<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":11,"featured_media":12272,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","footnotes":""},"categories":[29],"tags":[39,276,277],"class_list":["post-12263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-low-code","tag-filemaker","tag-scripting","tag-single-pass-loop"],"uagb_featured_image_src":{"full":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-1.png",1200,675,false],"thumbnail":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-1-150x150.png",150,150,true],"medium":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-1-300x169.png",300,169,true],"medium_large":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-1-768x432.png",768,432,true],"large":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-1-1024x576.png",1024,576,true],"1536x1536":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-1.png",1200,675,false],"2048x2048":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-1.png",1200,675,false],"woocommerce_thumbnail":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-1-300x300.png",300,300,true],"woocommerce_single":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-1-600x338.png",600,338,true],"woocommerce_gallery_thumbnail":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Single-Pass-Loop-1-100x100.png",100,100,true]},"uagb_author_info":{"display_name":"Weihao Ding","author_link":"https:\/\/www.directimpactsolutions.com\/en\/author\/weihao-dingdirectimpactsolutions-com\/"},"uagb_comment_info":0,"uagb_excerpt":"This article explains the technique known as a single-pass loop, and why it is part of my script template. If you do a lot of error trapping or exception handling, this is a great technique to master. The single-pass loop technique is inspired by the Try-Catch statement found in many programming languages. In a Try-Catch&hellip;","_links":{"self":[{"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/posts\/12263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/comments?post=12263"}],"version-history":[{"count":4,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/posts\/12263\/revisions"}],"predecessor-version":[{"id":18062,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/posts\/12263\/revisions\/18062"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/media\/12272"}],"wp:attachment":[{"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/media?parent=12263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/categories?post=12263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/tags?post=12263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}