LAB-09 DO WHILE loop I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.

Slides:



Advertisements
Similar presentations
Computer Science 101 While Statement. Iteration: The While-Statement The syntax for the While- Statement is while : The syntax for the While- Statement.
Advertisements

CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
CS107 Introduction to Computer Science Lecture 2.
UNIT 3 PROBLEM SOLVING WITH LOOP AND CASE LOGIC STRUCTURE
CS0004: Introduction to Programming Repetition – Do Loops.
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
LAB-04 IF Structure I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
ITC 240: Web Application Programming
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 ICS 101 – LAB 2 Arithmetic Operations I Putu Danu Raharja kfupm.edu.sa Information & Computer Science Department CCSE - King Fahd University.
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.
CS107 Introduction to Computer Science Loops. Instructions Pseudocode Assign values to variables using basic arithmetic operations x = 3 y = x/10 z =
BACS 287 Programming Logic 3. BACS 287 Iteration Constructs Iteration constructs are used when you want to execute a segment of code several times. In.
LAB-03 Logical Operations I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum.
Do Loop The syntax of DO loop: DO variable = initial_value, final_value[, increment] [statements] END DO Example: PROGRAM LINES ! Illustration of DO-loops.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
Iteration This week we will learn how to use iteration in C++ Iteration is the repetition of a statement or block of statements in a program. C++ has three.
CS150 Introduction to Computer Science 1
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Designing Algorithms Csci 107 Lecture 3. Designing algorithms Last time –Pseudocode –Algorithm: computing the sum 1+2+…+n –Gauss formula for 1+2+…+n Today.
CS 106 Introduction to Computer Science I 02 / 11 / 2008 Instructor: Michael Eckmann.
CHAPTER 6 REPETITIVE EXECUTION 6.1 Introduction A repetition structure or loop makes possible the repeated execution of one or more statements called the.
LAB-05 Function I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 6: Loop Control Structures.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
1 Lab Session-7 CSIT-121 Fall Introducing Structured Choice 4 The do~While Loop 4 Lab Exercises.
LAB-03 Logical Operations I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum.
LAB-12 2-D Array I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
LAB-10 1-D Array I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
Loops 1. Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved while Loop Flow.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
More While Loop Examples CS303E: Elements of Computers and Programming.
ORDER OF CONTENT AND INSTRUCTIONS A program in its simplest form usually contains three kinds of activity:  INPUT : The program asks the user for some.
Previously Repetition Structures While, Do-While, For.
Computer Science Department LOOPS. Computer Science Department Loops Loops Cause a section of your program to be repeated a certain number of times. The.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Count and add list of numbers From user input and from file.
ITI 1120 Lab #5 Contributors: S. Boyd, R. Plesa, A. Felty, D. Inkpen, A. Williams, D. Amyot.
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I 2/4/20161.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
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.
1 Chapter 8: File Processing Part 1. 2 Outline  Why Files?  Opening Files  Reading from Files  Writing to Files  Working with Multiple Files  Closing.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
Engineering Computing I Chapter 3 Control Flow. Chapter 3 - Control Flow The control-flow of a language specify the order in which computations are performed.
For loop. Exercise 1 Write a program to have the user input three (3) numbers: (f)rom, (t)o, and (i)ncrement. Count from f to t in increments of i, inclusive.
CONTENTS Loop Statements Parts of a loop Types of Loops Nested Loops
Computer Programming -1-
CHAPTER #7 Problem Solving with Loop. Overview Loop logical structure Incrementing Accumulating WHILE/WHILE-END FOR Nested loop Pointer Algorithmic instruction.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC530 Data Structures - LOOP 7/9/20161.
Exercise 2 : Using for loop Repetition (loop) (1)control variable initialization (2)Test Conditon (3)Modification of control variable value order : (1)
UCT Department of Computer Science Computer Science 1015F Iteration
C++ Programming: CS150 For.
Chapter 4: Algorithm Design
Structured Program Development in C
Unary Operators ++ and --
Repetition Control Structure
Chapter 4: Algorithm Design
CS150 Introduction to Computer Science 1
LAB-06 IF + Functions I Putu Danu Raharja
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Repetition (While Loop) LAB 9
REPETITION Why Repetition?
Presentation transcript:

LAB-09 DO WHILE loop I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals

ICS101-LAB09-Term073 2 Implicit DO…LOOP Printing or asking for a series of numbers READ*, (list of variables, index = initial, limit, increment) PRINT*, (list of variables, index = initial, limit, increment)

ICS101-LAB09-Term073 3 Example INTEGER I PRINT*, (I, I = 1, 10, 2) END

ICS101-LAB09-Term073 4 Introduction How is it to do a calculation until user gives certain input? With DO LOOP we can only do the loop in specific number of iterations. For above purpose, we need to use a logical condition Combining IF and GOTO (old versions) Using DO WHILE…END DO

ICS101-LAB09-Term073 5 Combining IF and GOTO NIF (condition) THEN BLOCK OF STATEMENTS GOTO N ENDIF

ICS101-LAB09-Term073 6 Example 1 SUM = 0 I = IF (I.LE. 99) THEN READ*, I SUM = SUM + I GOTO 100 ENDIF PRINT*, SUM END

ICS101-LAB09-Term073 7 Example 2 SUM = 0 I = 0 100IF (I.GT. 99) GOTO 110 READ*, I SUM = SUM + I GOTO PRINT*, SUM END

ICS101-LAB09-Term073 8 Using DO WHILE-END DO DO WHILE (condition) BLOCK OF STATEMENTS END DO

ICS101-LAB09-Term073 9 Example of DO WHILE-END DO INTEGER I, SUM SUM = 0 I = 0 DO WHILE (I.LE. 99) READ*, I SUM = SUM + I END DO PRINT*, SUM END

ICS101-LAB09-Term Exercises 1. Write a program that reads 10 real numbers from user and at the end, prints their sum, product, and average. Use DO-WHILE loop in this program. 2. Improve the above program of Q1 in the following way: Instead of just reading 10 numbers always, now the program should ask in advance from the user “How many numbers you want to enter?” Then the program should read as many numbers as user want. At the end, the program should print the sum, product and average of the entered numbers.

ICS101-LAB09-Term Exercises 3. Write a program that reads some numbers from users until –1 is entered. For each input number, the program should display its square. 4. There are M people in a town whose population increases by P percent each year. Write a program that displays the annual population and determines how many years (Y) it will take for the population to surpass S people.