LOOPS For EE 201 C10-1 SPRING 2012.

Slides:



Advertisements
Similar presentations
Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
Advertisements

Flow Charts, Loop Structures
CMPS 1371 Introduction to Computing for Engineers
MatLab – Palm Chapter 4, Part 3 For and While Loops
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
Introduction to Algorithm – part one Jennifer Elmer Form 3 Computing.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Programming with C# Iteration LECTURE 3. Summary of last lecture SequenceSelectionif and switch statementsCastingRandom.
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.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
1. Agenda for loop Short-handed notation How to use break and continue 2.
Chapter 8 Iteration Dept of Computer Engineering Khon Kaen University.
Visual Basic Programming
Chapter 2: General Problem Solving Concepts
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Chapter 6.  Control Structures are statements that are used to perform repetitive tasks and to make decisions within a program. Loop repeats a sequence.
Introduction to Loops For Loops. Motivation for Using Loops So far, everything we’ve done in MATLAB, you could probably do by hand: Mathematical operations.
ENG College of Engineering Engineering Education Innovation Center 1 Basic For Loops in MATLAB Programming in MATLAB / Chapter 6 Topics Covered:
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Repetition Repetition allows you to repeat an operation or a series of operations many times. This is called looping and is one of the basic structured.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
1 Conditional Statements + Loops ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem
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.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Computer Program Flow Control structures determine the order of instruction execution: 1. sequential, where instructions are executed in order 2. conditional,
EE 201 1C10-2 Spring 2012 LOOPS For.  Achieve Comprehension LOL of using Loops in programming. Class Learning Objectives 2C10-2 Spring 2012.
CSE 110: Programming Language I Matin Saad Abdullah UB 404.
Program Design & Development EE 201 C7-1 Spring
CHAPTER 6: REPETITION AND LOOP STATEMENTS Learning outcomes  Define the concept of repetition structure.  Specify.
The Repetition control structure using while loop.
Program design Program Design Process has 2 phases:
Chapter 9 Repetition.
Chapter 6: Loops.
REPETITION CONTROL STRUCTURE
Computer Application in Engineering Design
CHAPTER 6: REPETITION AND LOOP STATEMENTS
Repetition Structures Chapter 9
Chapter 4 MATLAB Programming
Pseudocode Upsorn Praphamontripong CS 1110 Introduction to Programming
Java's for Statement.
Chapter 5: Control Structure
Algorithms An algorithm is a sequence of steps written in the form of English phrases that specific the tasks that are performed while solving the problem.It.
REPETITION STATEMENTS
ALGORITHMS & FLOWCHARTING II
Ch 7: JavaScript Control Statements I.
( Iteration / Repetition / Looping )
Chapter 4 Repetition Structures
Chapter 5 Repetition.
Chapter 6 Repetition Objectives ❏ To understand basic loop concepts:
Control Structure Senior Lecturer
TOPIC 4: REPETITION CONTROL STRUCTURE
Algorithms and Flow Charts
JavaScript: Functions Part II
MATLAB – Basic For Loops
Repetition and Loop Statements
Chapter (3) - Looping Questions.
Loops CIS 40 – Introduction to Programming in Python
Introduction to Algorithms and Programming
Applications of User Defined functions in MATLAB
CS2011 Introduction to Programming I Loop Statements (II)
Introduction to Repetition Structures
CHAPTER 4 Iterative Structure.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Repetition Statements (Loops) - 2
PROGRAM FLOWCHART Iteration Statements.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Types of loops definite loop: A loop that executes a known number of times. Examples: Repeat these statements 10 times. Repeat these statements k times.
Presentation transcript:

LOOPS For EE 201 C10-1 SPRING 2012

Class Learning Objectives Achieve Comprehension LOL of using Loops in programming. C10-1 SPRING 2012

Session Agenda Contact before work 5 min. For statements 70 min. C10-1 SPRING 2012

Contact before work Burning Questions C10-1 SPRING 2012

Loops A loop is a structure for repeating a calculation a number of times. Each repetition of the loop is a pass(iteration). MATLAB uses two types of explicit loops: a-for loop: when the number of passes (iterations) is known ahead of time. b-while loop : when the looping process must terminate when a specified condition is satisfied, and thus the number of passes is not known in advance. C10-1 SPRING 2012

For loops When we wish to repeat a set of instructions for a set number of times we generally use a for loop. The Syntax: for loop variable=initial value: increment value: end value statements end C10-1 SPRING 2012

Flow chart for loop variable=initial value: increment value: end value statements end Loop variable= Initial value Loop variable<=end value loop variable=loop variable+increment value T statements F end C10-1 SPRING 2012

A simple example of a for loop is T Start K <=35 X = K ^ 2 End K = K + 10 K=5 % for loop for k = 5:10:35 % compute x = k^2 end C10-1 SPRING 2012

A simple example of a for loop is 1st iteration Start K <=35 X = K ^ 2 End K = K + 10 K=5 % for loop for k = 5:10:35 % compute x = k^2 end K=5 K=15 K=5 K=5 K=15 X=25 X=25 C10-1 SPRING 2012

A simple example of a for loop is 2nd iteration Start K <=35 X = K ^ 2 End K = K + 10 K=5 % for loop for k = 5:10:35 % compute x = k^2 end K=25 K=15 K=15 K=25 X=225 X=225 C10-1 SPRING 2012

A simple example of a for loop is 3rd iteration Start K <=35 X = K ^ 2 End K = K + 10 K=5 % for loop for k = 5:10:35 % compute x = k^2 end K=35 K=25 K=25 K=35 X=625 X=625 C10-1 SPRING 2012

A simple example of a for loop is 4th iteration Start K <=35 X = K ^ 2 End K = K + 10 K=5 % for loop for k = 5:10:35 % compute x = k^2 end K=45 K=35 K=35 K=45 X=1225 X=1225 C10-1 SPRING 2012

A simple example of a for loop is 5th iteration Start K <=35 X = K ^ 2 End K = K + 10 K=5 % for loop for k = 5:10:35 % compute x = k^2 end K=45 K=45 C10-1 SPRING 2012

Trace the previous example program and fill in the table below, which shows how the program variables change over the time of the execution of the program. Iteration# k x C10-1 SPRING 2012

Iteration# k x 1 5 25 2 15 225 3 625 4 35 1225 C10-1 SPRING 2012

Example Draw a flowchart and Write a MATLAB program that finds the sum of first 50 natural numbers. C10-1 SPRING 2012

Flowchart OR C10-1 SPRING 2012

C10-1 SPRING 2012