Loops and Character Manipulation - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Loops and Character Manipulation

Description:

While Loops - code block is repeated as long as loop condition is satisfied ... algebraically add increment to index, go to Step 2. ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 24
Provided by: macli
Category:

less

Transcript and Presenter's Notes

Title: Loops and Character Manipulation


1
  • Loops and Character Manipulation
  • 4.1 Control Constructs Loops
  • While Loops - code block is repeated as long as
    loop condition is satisfied
  • Iterative Loops - code block repeated a
    pre-specified number of times (hopefully and/or
    maybe)
  • 4.1.1 The WHILE Loop
  • DO
  • Statement Block 1
  • IF (logical expression) EXIT
  • Statement Block 2
  • END DO
  • Execution Steps
  • Execute Statement Block 1
  • If logical expression is True, transfer to
    Statement after END DO.
  • If logical expression is False, Execute Statement
    Block 2.
  • Repeat Steps 1-4.

2
(No Transcript)
3

4
(No Transcript)
5
(No Transcript)
6
(No Transcript)
7
  • The DO WHILE Loop
  • General Form
  • DO WHILE (logical expression)
  • Statement Block
  • END DO
  • If the logical expression is True at the point of
    the DO WHILE, the Statement Block is executed.
    If it is False, the statement after the END DO is
    executed.
  • 4.1.3 The Iterative or Counting Loop
  • DO indexistart, iend, increment
  • Statement Block
  • END DO
  • Index gt loop index (counter)
  • Istart gt beginning value of index
  • Iend gt terminating value of index
  • Increment gt increment added to index after each
    execution of Statement Block.

8
  • Execution Steps
  • index set to istart.
  • if indexincrement lt iendincrement, go to Step
    3.
  • If indexincrement gt iendincrement, go to
    Statement after END DO.
  • Statement Block executed.
  • algebraically add increment to index, go to Step
    2.
  • What parameters would allow a DO Loop to never
    execute?

9
(No Transcript)
10
(No Transcript)
11
(No Transcript)
12
(No Transcript)
13
(No Transcript)
14
  • Hints on Looping
  • Indent Statement Block on all Block Constructs,
    i.e., IF, DO, etc.
  • Never change the DO Loop parameters within a DO
    loop. In many cases, compilers cannot detect
    this change!
  • Number of Iterations (iend istart incr) /
    incr
  • If the Number of Iterations lt 0, Statement Block
    is not executed.
  • Parameters should be integer variables. (Some
    compilers allow)
  • Branching out of the range of a DO Loop is
    permissible. The index variable maintains its
    last value.
  • After a normal DO Loop completion, the index
    variable is undefined!
  • Branching into the range of a DO Loop is not
    permissible! Compilers will catch this one

15
  • CYCLE and EXIT Statements
  • CYCLE Statement inside DO or WHILE loops
  • 1) Increment that loops index variable
  • Resume execution at top of that loop, i.e.,
    check index variable for loop completion and
    execute that loop if appropriate
  • EXIT Statement inside DO or WHILE loops
    Immediate transfer to first statement after that
    loop.

16
  • Named Loops, Nested Loops and Block IF Constructs
  • L1 DO
  • L2 DO
  • IF (logical expression 1) THEN
  • Statement 1
  • Statement 2
  • L3 DO IL312,7,-3
  • Statement 1
  • Statement 2
  • END DO L3
  • ELSE IF (logical expression 2) THEN
  • Statement 1
  • Statement 2
  • END IF
  • DO IL41,100,3
  • Statement 1
  • Statement 2

17
  • Character Assignments and Character
    Manipulations
  • 4.2.1 Character Assignments
  • General Form Character variable name character
    expression
  • A B If A is longer than B, A is padded with
    blanks.
  • If A is shorter than B, extra characters in B are
    truncated.
  • 4.2.2 Substring Specifications
  • Character_variable_name (char1 char2)
  • Read as The character string in
    character_variable_name from
  • char1 to char2, inclusive.

18
(No Transcript)
19
  • The Concatenation Operator (//)
  • ConcatenationgtTack one character string onto the
    tail end of another string.

20
(No Transcript)
21
  • 4 Relational Operators with Character Data
  • Comparison result dependent on the collating
    sequence on the computer.
  • See Text, Appendix A, ASCII and EBCDIC Coding
    Systems, p 719.

22
Character Intrinsic Functions
23
  • DeBugging Fortran Loops
  • WHILE Loops Probable error in Logical
    Expression.
  • Iterative Loops Probable error in loop
    parameters.
Write a Comment
User Comments (0)
About PowerShow.com