# Please, No More Loops (Than Necessary): New Patterns in Fortran 2023

**URL:** <https://fortran-lang.discourse.group/t/please-no-more-loops-than-necessary-new-patterns-in-fortran-2023/10605>\
**Category:** Uncategorized\
**Created:** [January 7, 2026, 8:08pm UTC](https://fortran-lang.discourse.group/t/please-no-more-loops-than-necessary-new-patterns-in-fortran-2023/10605 "2026-01-07T20:08:38Z")\
**Posts on this page:** 1\
**Showing post:** 30

<div class="post-metadata">

**Author:** ![zaikunzhang](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/zaikunzhang/32/785_2.png) [@zaikunzhang](https://fortran-lang.discourse.group/u/zaikunzhang)\
**Post date:** [January 24, 2026, 8:29am UTC](https://fortran-lang.discourse.group/t/please-no-more-loops-than-necessary-new-patterns-in-fortran-2023/10605/30 "2026-01-24T08:29:31Z")

</div>

Nice talk @rouson !

[The PRIMA project](https://www.libprima.net) **followed strictly the “No More Loops (Than Necessary)” principle**. It is nice to know that the same rule has been adopted in Berkeley Lab.

I also take the viewpoint that loops should be replaced with array (matrix/vector) operations whenever possible.

Quoting my old post “[Automatic arrays and intrinsic array operations: to use or not to use?](https://fortran-lang.discourse.group/t/automatic-arrays-and-intrinsic-array-operations-to-use-or-not-to-use/4070/1)”:

> [@Automatic arrays and intrinsic array operations: to use or not to use?](https://fortran-lang.discourse.group/t/automatic-arrays-and-intrinsic-array-operations-to-use-or-not-to-use/4070/1):
>
> For me, **one of the core strengths of Fortran is its native support for matrices and matrix/vector operations**. By “native support for matrices”, I mean particularly automatic arrays — to get a matrix, you do not need to do anything more than declaring it. As for matrix/vector operations, I mean intrinsic array operations such as `matmul`, `transpose`, `dot_product`, and broadcasting.
> 
> Thanks to such support, we can write scientific computing code in a way that is very similar to how the algorithms are formulated in mathematics. Without such support, a language should not be called a “Formula Translator”.
> 
> Take matrix/vector operations as an example. Without intrinsic support for them, we have to either re-invent these wheels ourselves, or code them as loops whenever such operations appear in an algorithm. However, as a mathematician, I can tell that **mathematicians rarely consider matrix/vector operations as loops** — loops are only how we calculate them, but not how we define/understand them. Loops are used only when we describe truly iterative algorithms, e.g., CG, steepest descent, …
> 
> Not surprisingly, most other popular languages in scientific computing are also strong at supporting matrices and matrix/vector operations. My most familiar language is MATLAB — if you call it a language. It supports almost all matrix/vector operations you can name. A well-knowledged MATLAB programmer can code a sophisticated algorithm without using any loop but only using matrix/vector operations.
> 
> Indeed, as a common principle in MATLAB programming, you should **never** code a matrix/vector operation in loops. **It is a bad practice to re-invent any tool that the language intrinsically provides.** You may argue that this is because MATLAB is slow at loops as a scripting language. But I understand it from a more philosophical perspective: **why does the language provide the functionality if we are not encouraged to use it?**

---

_[View the full topic](https://fortran-lang.discourse.group/t/please-no-more-loops-than-necessary-new-patterns-in-fortran-2023/10605)._
