Chapter 4 Loops and Character Manipulation Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.

Slides:



Advertisements
Similar presentations
Chapter 41 Variables and JSP Control Structures JavaServer Pages By Xue Bai.
Advertisements

CS0004: Introduction to Programming Repetition – Do Loops.
Chapter 4. Loops and Character Manipulation Loops in FORTRAN are constructs that permits us to execute a sequence of statements more than once. Type of.
Chapter 5 Basic I/O Concepts Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul - Turkey Tel:
Chapter 4 Repetitive Execution. 2 Types of Repetition There are two basic types of repetition: 1) Repetition controlled by a counter; The body of the.
Chapter 8 Introduction to Arrays Part II Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Chapter 10 Additional Features of Arrays Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Chapter 3 Program Design and Branching Structures Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering.
Chapter 5: Control Structures II (Repetition)
Chapter 7 Introduction to Arrays Part I Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Chapter 2 Basic Elements of Fortan
Loops – While, Do, For Repetition Statements Introduction to Arrays
Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
16/27/ :53 PM6/27/ :53 PM6/27/ :53 PMLogic Control Structures Arithmetic Expressions Used to do arithmetic. Operations consist of +,
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
Chapter 9 Introduction to Procedures Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul -
Chapter 6 AN INTRODUCTION TO FILES AND FILE PROCESSING Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering.
Control Structures - Repetition Chapter 5 2 Chapter Topics Why Is Repetition Needed The Repetition Structure Counter Controlled Loops Sentinel Controlled.
Loops are MATLAB constructs that permit us to execute a sequence of statements more than once. There are two basic forms of loop constructs: i. while.
Fundamentals of Python: From First Programs Through Data Structures
Fundamentals of Python: First Programs
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 5 Control Structures: Loops 5.1 The while Loop The while loop is probably the most frequently used loop construct. The while loop is a conditional.
PL/SQL Loops. Building Logical Conditions All logical conditions must yield a boolean condition. You can build a simple Boolean condition by combining.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Compunet Corporation1 Programming with Visual Basic.NET While, Do and For – Next Loops Week 5 Tariq Ibn Aziz.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
Program Flow Control - Looping Addis Ababa Institute of Technology Yared Semu April 2012.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
I Power Higher Computing Software Development High Level Language Constructs.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 5A Repetition (Concepts)
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
Introduction to Computer Sciences References: [1] Fortran 95/2003 for Scientists and Engineers (3e) by Stephen J. Chapman. [2] Using Fortran 90 by Chester.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Fortran: Control Structures Session Three ICoCSIS.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
Chapter 6: Loops.
Chapter 4 Repetition Statements (loops)
Chapter 3: Decisions and Loops
Warm-up Program Use the same method as your first fortune cookie project and write a program that reads in a string from the user and, at random, will.
Ch 7: JavaScript Control Statements I.
Computer Science Faculty
JavaScript: Control Statements.
Control Structures - Repetition
Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski.
Arrays, For loop While loop Do while loop
Outline Altering flow of control Boolean expressions
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Iteration: Beyond the Basic PERFORM
Chapter 8: More on the Repetition Structure
Chapter 6: Repetition Statements
Flow of Control.
More Loops Topics Counter-Controlled (Definite) Repetition
Introduction to Computer Science
Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski.
Conditional Loops Counted Loops
More Loops Topics Counter-Controlled (Definite) Repetition
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
Repetition Structures
More Loops Topics Counter-Controlled (Definite) Repetition
REPETITION Why Repetition?
Presentation transcript:

Chapter 4 Loops and Character Manipulation Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul - Turkey Tel: +90 ( ) Fax: +90 ( )

Loops and Character Manipulation CONTROL CONSTRUCTS: LOOPS Loops are Fortran constructs that permit us to execute a sequence of statements more than once. There are two basic forms of loop constructs : while loops and iterative loops (or counting loops). The major difference between these two types of loop is in how the repetition is controlled. The code in a while loop is repeated an indefinite number of times until some user-specified condition is satisfied. By contrast, the code in an iterative loop is repeated a specified number of times, and the number of repetitions is known before the loop starts. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 2

Loops and Character Manipulation The While Loop A while loop is a block of statements that are repeated indefinitely as long as some condition is satisfied. A while loop may contain one or more EXIT statements to terminate its execution. Each EXIT statement is usually a part of an IF statement or block of construct. If the logicaI_expr in the IF is false when the statement is executed, the loop continues to execute. If the logicaI_expr in the IF is true when the statement is executed. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 3

Loops and Character Manipulation Example: Statistical Analysis the average (or arithmetic mean) and the standard deviation of the set of measurements. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 4

Loops and Character Manipulation The Do While Loop There is an alternative form of the while loop in Fortran, called the DO WHILE loop. The DO WHILE construct has the form If the logical expression is true, statements 1 through n will be executed, and then control will return to the DO WHILE statement. If the logical expression is still true, the statements will be executed again. This process will be repeated until the logical expression becomes false. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 5

Loops and Character Manipulation The Iterative or Counting Loop In the Fortran language, a loop that executes a block of statements a specified number of times is called an iterative DO loop or a counting loop. The counting loop construct has the form where index is an integer variable used as the loop counter (also known as the loop index). The integer quantities is istart, iend, and incr are the parameters of the counting loop. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 6

Loops and Character Manipulation First, consider the following example: In this case, statements 1 through n will be executed 10 times. The index variable I will be 1 on the first time, 2 on the second time, and so on. The index variable will be 10 on the last pass through the statements. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 7

Loops and Character Manipulation Second, consider the following example: In this case, statements 1 through n will be executed five times. The index variable I will be 1 on the first time, 3 on the second time, and so on. The index variable will be 9 on the fifth and last pass through the statements. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 8

Loops and Character Manipulation Third, consider the following example: Here, statements 1 through n will never be executed, since index*incr > iend*incr on the very first time that the DO statement is reached. Instead, control will transfer to the first statement after the END DO statement. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 9

Loops and Character Manipulation Finally, consider the following example: In this case, statements 1 through n will be executed four times. The index variable I will be 3 on the first time, 1 on the second time, -1 on the third time, and - 3 on the fourth time. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 10

Loops and Character Manipulation Example: The Factorial Function The factorial function is defined as © 2010, Dr. ALİ CAN TAKİNACI Slide No: 11

Loops and Character Manipulation The CYCLE and EXIT Statements If the CYCLE statement is executed in the body of a DO loop, the execution of the current iteration of the loop will stop, and control will be returned to the top of the loop. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 12

Loops and Character Manipulation If the EXIT statement is executed in the body of a loop, the execution of the loop will stop and control will be transferred to the first executable statement after the loop. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 13

Loops and Character Manipulation Named Loops It is possible to assign a name to a loop. The general form of a while loop with a name attached is name may be up to 31 alphanumeric characters long, beginning with a letter. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 14

Loops and Character Manipulation Nesting Loops and Block IF Constructs It is possible for one loop to be completely inside another loop. If one loop is completely inside another one, the two loops are called nested loops. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 15

Loops and Character Manipulation CHARACTER ASSIGNMENTS AND CHARACTER MANIPULATIONS Character data can be manipulated by using character expressions. A character expression can be any combination of valid character constants, character variables, character operators, and character functions. A character operator is an operator on character data that yields a character result. There are two basic types of character operators: substring specifications and concatenation. Character functions are functions that yield a character result. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 16

Loops and Character Manipulation Character Assignments A character expression may be assigned to a character variable with an assignment statement. If the character expression is shorter than the length of the character variable to which it is assigned, then the rest of the variable is padded out with blanks. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 17

Loops and Character Manipulation Substring Specifications A substring specification selects a portion of a character variable, and treats that portion as if it were an independent character variable. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 18

Loops and Character Manipulation © 2010, Dr. ALİ CAN TAKİNACI Slide No: 19

Loops and Character Manipulation The Concatenation (//) Operator It is possible to combine two or more strings or substrings into a single large string. This operation is known as concatenation. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 20

Loops and Character Manipulation Relational Operators with Character Data In standard Fortran, character strings may be compared with character strings, and numbers may be compared with numbers, but character strings may not be compared to numbers. The comparison is based on the collating sequence of the characters on the computer where the program is being executed. For example, the character ‘A’ is character number 65 in the ASCII character set, while the character ‘B' is character number 66 in the set (see Appendix A). Therefore, the logical expression ‘A’ < ‘B’ is true in the ASCII character set. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 21

Loops and Character Manipulation On the other hand, the character ‘a’ is character number 97 in the ASCII set, so 'a' < 'A' is false in the ASCII character set. Function ACHAR(i) accepts an integer value i, and returns the character at that position in the ASCII character set. For example, the function ACHAR(65) returns the character 'A', because 'A' is the 65th character in the ASCII character set. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 22