# <span class='text-muted'>003.</span> `do` loop

<span style='font-size: small;' class='text-muted'>topic: {ref}`loops`</span>

The primary looping construct in Fortran is `do` ... `end do`.
A program to print the sum the squares of the integers from 1 to 5 is

```{literalinclude} ../../src/do-enddo.f90
:language: fortran
:caption: do-enddo.f90 | <a href="https://github.com/zmoon/FortranTipBrowser/blob/main/src/do-enddo.f90" target="_blank" title="See this source on GitHub"><i class="fab fa-github"></i></a> | <a href="https://godbolt.org/#g:!((g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:fortran,selection:(endColumn:1,endLineNumber:11,positionColumn:1,positionLineNumber:11,selectionStartColumn:1,selectionStartLineNumber:11,startColumn:1,startLineNumber:11),source:'implicit+none%0A%0Ainteger+::+i,+ssq%0A%0Assq+%3D+0%0Ado+i+%3D+1,+5%0A+++ssq+%3D+ssq+%2B+i**2%0Aend+do%0Aprint+*,+%22sum+of+squares+is+%22,+ssq%0A%0Aend%0A'),l:'5',n:'0',o:'Fortran+source+%231',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:gfortran112,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'0',intel:'0',libraryCode:'0',trim:'1'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:fortran,libs:!(),options:'',selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1,tree:'1'),l:'5',n:'0',o:'x86-64+gfortran+11.2+(Fortran,+Editor+%231,+Compiler+%231)',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',m:62.300683371298405,n:'0',o:'',t:'0'),(g:!((h:output,i:(compiler:1,editor:1,fontScale:14,fontUsePx:'0',tree:'1',wrap:'1'),l:'5',n:'0',o:'Output+of+x86-64+gfortran+11.2+(Compiler+%231)',t:'0')),header:(),l:'4',m:37.699316628701595,n:'0',o:'',s:0,t:'0')),l:'3',n:'0',o:'',t:'0')),version:4" target="_blank" title="Open in Godbolt Compiler Explorer"><img src="https://raw.githubusercontent.com/compiler-explorer/compiler-explorer/main/views/resources/site-logo.svg" alt="Godbolt Compiler Explorer logo" width="55.11" height="16.7" class="align-text-bottom" /></a> | <a href="https://play.fortran-lang.org/?code=implicit%20none%0A%0Ainteger%20%3A%3A%20i%2C%20ssq%0A%0Assq%20%3D%200%0Ado%20i%20%3D%201%2C%205%0A%20%20%20ssq%20%3D%20ssq%20%2B%20i%2A%2A2%0Aend%20do%0Aprint%20%2A%2C%20%22sum%20of%20squares%20is%20%22%2C%20ssq%0A%0Aend%0A" target="_blank" title="Open in Fortran Playground"><img src="https://raw.githubusercontent.com/fortran-lang/playground/main/frontend/src/fortran-logo.png" alt="Fortran logo" height="15.5" class="align-text-bottom" /></a>
```

```{code-block} text
:caption: Output[^gfortran-version]

 sum of squares is           55

```

[^gfortran-version]: Compiled using `GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0` with no flags

---

<blockquote class="twitter-tweet"><p lang="en" dir="ltr">The primary looping construct in Fortran is do ... end do. A program to print the sum the squares of the integers from 1 to 5 is<br><br>implicit none<br>integer :: i,ssq<br>ssq = 0<br>do i=1,5<br> ssq = ssq + i**2<br>end do<br>print*,&quot;sum of squares is &quot;,ssq<br>end</p>&mdash; FortranTip (@fortrantip) <a href="https://twitter.com/fortrantip/status/1471891644370796550?ref_src=twsrc%5Etfw">December 17, 2021</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>