Fortran DO Statements (how many loop times)

  • Context: Comp Sci 
  • Thread starter Thread starter rk2ray
  • Start date Start date
  • Tags Tags
    Fortran Loop
Click For Summary
SUMMARY

The discussion focuses on the execution count of various Fortran DO statements, specifically analyzing the loops defined in the examples provided. The loops are evaluated based on their index variables and increment values. For instance, the loop "DO irange = -32768, 32767" executes 65536 times, while "DO j = 100, 1, -10" runs 10 times. The statement "DO count = 2, 3, 4" executes once, and "DO index = -4, -7" does not execute at all. The loop "DO i = -10, 10, 10" runs 2 times, confirming the importance of understanding loop increments in Fortran.

PREREQUISITES
  • Understanding of Fortran programming language syntax
  • Knowledge of integer data types in programming
  • Familiarity with loop constructs in programming
  • Basic comprehension of increment and decrement operations
NEXT STEPS
  • Study Fortran DO loop syntax and execution rules
  • Learn about integer data types and their implications in Fortran
  • Explore advanced loop constructs in Fortran, such as nested loops
  • Investigate performance considerations for loop execution in Fortran
USEFUL FOR

This discussion is beneficial for Fortran programmers, computer science students, and anyone interested in understanding loop execution mechanics in programming languages.

rk2ray
Messages
7
Reaction score
0
Hello,

Examining the following DO statements and determining how many times each loop will be executed. Assume that all loop index variables are integers.

(a) DO irange = -32768, 32767
(b) DO j = 100, 1, -10
(c) DO count = 2, 3, 4
(d) DO index = -4, -7

(e) DO i = -10, 10, 10
The loop will take 10 increments and will run 2 times.

Thanks for any help.
 
Last edited:
Physics news on Phys.org
If you don't try to evaluate at least one or two of the easy statements, you won't get any help on the harder ones.
 

Similar threads

Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
6K
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 21 ·
Replies
21
Views
3K