# \`block\` syntax and my confusion

**URL:** <https://fortran-lang.discourse.group/t/block-syntax-and-my-confusion/1121>\
**Category:** Help\
**Created:** [April 29, 2021, 1:00pm UTC](https://fortran-lang.discourse.group/t/block-syntax-and-my-confusion/1121 "2021-04-29T13:00:50Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![lkedward](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/lkedward/32/72_2.png) [@lkedward](https://fortran-lang.discourse.group/u/lkedward)\
**Post date:** [April 29, 2021, 1:41pm UTC](https://fortran-lang.discourse.group/t/block-syntax-and-my-confusion/1121/4 "2021-04-29T13:41:31Z")

</div>

Hi @zoziha, welcome to the Discourse!  
You may find this previous answer of mine relevant:

> [@Arbitrary sized array](https://fortran-lang.discourse.group/t/arbitrary-sized-array/59/13):
>
> My understanding is that the block construct simply allows programmers to organise code by grouping declarations and statements together within a defined local scope. This can have some advantages: It avoids large declaration blocks at the beginning of programs and procedures; it is easier to reason which variables are used in which execution statements when reading the code; it limits the scope of variables so they can’t accidentally be used elsewhere; it can be useful for objects w…

See also this particular use case where `block` was uniquely helpful for scoping:

> [@Best practices for passing C strings](https://fortran-lang.discourse.group/t/best-practices-for-passing-c-strings/104/11):
>
> [Steve’s recent blog post](https://stevelionel.com/drfortran/2020/06/07/doctor-fortran-in-no-reserve/) might be relevant here regarding the intrinsic keyword. Would this modification work perhaps? block intrinsic trim if (trim\_) then f\_c\_string = trim(string)//c\_null\_char else f\_c\_string = string//c\_null\_char end if end block

and this answer about local scope in `do concurrent`:

> [@Arbitrary sized array](https://fortran-lang.discourse.group/t/arbitrary-sized-array/59/16):
>
> If you want to have thread-local variables inside a do concurrent you have to use the block construct.

---

_[View the full topic](https://fortran-lang.discourse.group/t/block-syntax-and-my-confusion/1121)._
