Do Loop The syntax of DO loop: DO variable = initial_value, final_value[, increment] [statements] END DO Example: PROGRAM LINES ! Illustration of DO-loops.

Slides:



Advertisements
Similar presentations
Programming In C++ Spring Semester 2013 Lecture 3 Programming In C++, Lecture 3 By Umer Rana.
Advertisements

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.
Objectives In this chapter, you will learn about:
Repeating Actions While and For Loops
Computer Science 1620 Loops.
1 Parts of a Loop (reminder) Every loop will always contain three main elements: –Priming: initialize your variables. –Testing: test against some known.
Types of LOOP Structures Do While ……. Loop Do Until …… Loop For …… Next loop.
CS150 Introduction to Computer Science 1
Introduction to Computers and Programming for Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to.
1 Lecture 16 Chapter 6 Looping Dale/Weems/Headington.
CHAPTER 6 REPETITIVE EXECUTION 6.1 Introduction A repetition structure or loop makes possible the repeated execution of one or more statements called the.
For Next Looping My first Looping Structure. For…Next FOR counter_variable = initial_value TO end_value STEP increment Statement-1 Statement-2 ……. Statement-n.
27 March, 2000 CS1001 Lecture 9 Lab 2 Complete Lecture 8 DO Loops –Counter-controlled DO loop –Depreciation example -- details –Nested loops –Examples.
Revision – A simple program How to start a program? How to end a program? How to declare variables? What are the mathematical operators? How to start a.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Chapter 6 - Visual Basic Schneider
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do While and Do Until Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops.
PL/SQL Loops. Building Logical Conditions All logical conditions must yield a boolean condition. You can build a simple Boolean condition by combining.
Programming Logic and Design Fifth Edition, Comprehensive
Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
Chapter 5 Loops.
More While Loop Examples CS303E: Elements of Computers and Programming.
Programming Logic and Design Sixth Edition Chapter 5 Looping.
Nested LOOPS.
Looping II (for statement). CSCE 1062 Outline  for statement  Nested loops  Compound assignment operators  Increment and decrement operators.
Copyright © Nancy Acemian 2004 For Loops-Break-Continue COMP For loop is a counter controlled loop. For loop is a pretest loop. Used when number.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Chapter 8 Iteration Dept of Computer Engineering Khon Kaen University.
Repetition Structures Repetition Structures allow you to write programs that will repeat program steps multiple times. –Also called Loops –Counter controlled.
Bordoloi and Bock Control Structures: Iterative Control.
6.2 For…Next Loops General Form of a For…Next Loop
Loops cause a section of a program to be repeated a certain number of times. The repetition continues while a condition remains true. When a condition.
Counting Loops.
REPETITION STATEMENTS - Part2 Structuring Input Loops Counter-Controlled Repetition Structure Sentinel-Controlled Repetition Structure eof()-Controlled.
For Loop Tips And Tricks
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
PGT C Programming1 Week 4 – Repetition Structures / Loops.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
Pendalaman Materi Conditional dan Repetition (Pengulangan)
1 Looping Chapter 6 2 Getting Looped in C++ Using flags to control a while statement Trapping for valid input Ending a loop with End Of File condition.
Sesi 0607EKT120/4 Computer Programming Week 5 – Repetition / Loops.
Computer Programming -1-
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
UCT Department of Computer Science Computer Science 1015F Iteration
Chapter 9 Repetition.
Fundamentals of PL/SQL part 2 (Basics)
CSC111 Quick Revision.
CHAPTER 5A Loop Structure
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Week 4 – Repetition Structures / Loops
ALGORITHMS & FLOWCHARTING II
INC 161 , CPE 100 Computer Programming
Chapter 5 Repetition.
Repetition and Loop Statements
Outline Altering flow of control Boolean expressions
The for-loop and Nested loops
Chapter 9 Control Structures.
Structured Program Development in C
INC 161 , CPE 100 Computer Programming
Case & Repetitive Statements
Loops.
Console.WriteLine(“Good luck!”);
Loop Construct.
Repetition (While Loop) LAB 9
Presentation transcript:

Do Loop The syntax of DO loop: DO variable = initial_value, final_value[, increment] [statements] END DO Example: PROGRAM LINES ! Illustration of DO-loops IMPLICIT NONE INTEGER L ! a counter DO L = 1, 100 ! start of repeated section PRINT *, L, ' I must not talk in class' END DO ! end of repeated section END PROGRAM LINES start declare L L = 1 L>100 ? L, ‘ I must not talk in class’ L = L + 1 stop DO Loop yes no initial value of L is 1. final value of L is 100. increment of L is 1.

Do Loop The syntax of DO loop: DO label variable = initial_value, final_value[, increment] [statements] labelCONTINUE Example: PROGRAM LINES ! Illustration of DO-loops IMPLICIT NONE INTEGER L ! a counter DO 100 L = 1, 100 ! start of repeated section PRINT *, L, ' I must not talk in class' 100CONTINUE ! end of repeated section END PROGRAM LINES

Do Loop - flowchart start declare L L, ‘ I must not talk in class’ stop loop DO L=1,10 0 exit start declare L L = 1 L>100 ? L, ‘ I must not talk in class’ L = L + 1 stop DO Loop yes no initial value of L is 1. final value of L is 100. increment of L is 1.

Nested Do Loops start declare L, K stop loop DO L=1,10 0 exit DO K=1,10 0 L, K, ‘ I must not talk in class’ loop DO L = 1, 100 DO K = 1, 100 PRINT *, L,K, ' I must not talk in class‘ END DO

Examples 1.N: input from keyboard; calculate sum=1+2+3+….N Read(*,*) N Sum = 0 Do i = 1, N Sum = sum + i End Do 2. N: input from keyboard; calculate res=1*2*3*….*N Read(*,*) N res = 1 Do i = 1, N res = res * i End Do

Examples 3. If N = 10, what is the output of the program? Read(*,*) N Sum = 0 Do i = N, 2, -2 Sum = sum + i End Do Ans: 30 ( )

Examples 4. What is the output of the program? DO I = 1, 3! start of outer loop PRINT *, '**********I = ', I, '********' DO J = 1, 2! start of inner loop PRINT *, I, ' * ',J, ' = ', I*J END DO PRINT * ! a blank line END DO ! end of repeated section Ans: **********I = 1 ******** 1*1 = 1 1*2 = 2 **********I = 2 ******** 2*1 = 2 2*2 = 4 **********I = 3 ******** 3*1 = 3 3*2 = 6

Examples 5. What is the output of the program? X0 = 0.0 ! set initial value DX = 0.2! set increment DO I = 1, 10, 2 ! start of repeated section X = X0 + (I - 1) * DX ! actual value to be output PRINT *, X END DO Ans: 0.0(i=1) 0.4(i=3) 0.8 ……. 1.6(i=9)