EE 201 1C10-2 Spring 2012 LOOPS For.  Achieve Comprehension LOL of using Loops in programming. Class Learning Objectives 2C10-2 Spring 2012.

Slides:



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

Looping Structures: Do Loops
CMPS 1371 Introduction to Computing for Engineers
 Control structures  Algorithm & flowchart  If statements  While statements.
Repeating Actions While and For Loops
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?
CS1061: C Programming Lecture 8: Repetition A. O’Riordan, 2004.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Functions Outline 3.12Recursion 3.13Example Using Recursion: The Fibonacci Series 3.14Recursion.
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
An ordered sequence of unambiguous and well-defined instructions that performs some task and halts in finite time Let's examine the four parts of this.
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Recursion Review.
Flow of Control. 2 Control Structures Control structure: An instruction that determines the order in which other instructions in a program are executed.
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Lecture6 Recursion function © by Pearson Education, Inc. All Rights Reserved. 1.
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.
For Loops 1 ENGR 1181 MATLAB 8. For Loops and Looped Programming in Real Life Looping within programs has long been a useful tool for completing mundane.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
 An instruction or group of instructions.  Computer executes program repeatedly for specified number of times. Or until some terminating conditions are.
CSE 102 Introduction to Computer Engineering What is an Algorithm?
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.
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,
Loop.  While Loop  Do-while Loop  For Loop Continue Statement Conclusion Loop Loop.
Basic Control Structures
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
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.
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
1 Looping Dale/Weems/Headington. 2 KA/JS/P Warning l Save your work often! l In the Khan Academy, JavaScript environment, infinite loops will lock up.
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Course Title Object Oriented Programming with C++ Course instructor ADEEL ANJUM Chapter No: 04 loops 1 BY ADEEL ANJUM ( MSc - cs, CCNA, WEB DEVELOPER )
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
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.
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.
Computer Program Flow Control structures determine the order of instruction execution: 1. sequential, where instructions are executed in order 2. conditional,
Sesi 0607EKT120/4 Computer Programming Week 5 – Repetition / Loops.
CONTENTS Loop Statements Parts of a loop Types of Loops Nested Loops
Program Design & Development EE 201 C7-1 Spring
Control Structures: Examples. for-loop example Q: If a=1, b=3, and x=7, what is the value of x when the loop terminates? A: x=1 for(k=a; k
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
Topic : While, For, Do-While Loop Guided By : Branch : Batch :
Program design Program Design Process has 2 phases:
Chapter 9 Repetition.
Chapter 6: Loops.
ALGORITHMS AND FLOWCHARTS
CHAPTER 5A Loop Structure
Repetition-Counter control Loop
Ch 7: JavaScript Control Statements I.
( Iteration / Repetition / Looping )
Web Programming– UFCFB Lecture 16
Chapter 5 Repetition.
Outline Altering flow of control Boolean expressions
MATLAB – Basic For Loops
Structured Program Development in C
Chapter (3) - Looping Questions.
CHAPTER 4 Iterative Structure.
PROGRAM FLOWCHART Iteration Statements.
Repetition (While Loop) LAB 9
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.
For...Next Statements.
LOOPS For EE 201 C10-1 SPRING 2012.
REPETITION Why Repetition?
Presentation transcript:

EE 201 1C10-2 Spring 2012 LOOPS For

 Achieve Comprehension LOL of using Loops in programming. Class Learning Objectives 2C10-2 Spring 2012

Session Agenda  Contact before work 5 min.  For statements 70 min. 3C10-2 Spring 2012

Contact before work  Burning Questions 4C10-2 Spring 2012

Loops  A loop is a structure that repeats the execution of One or More statements for 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. 5C10-2 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 variable = initial value: increment value: end value statements end 6C10-2 Spring 2012

Flow chart Loop variable <=end value Loop variable= Initial value statements loop variable=loop variable+increment end T F 7C10-2 Spring 2012

 Write a MATLAB program that computes the sum Of odd numbers from 1-10 then evaluates and displays the average? 8C10-2 Spring 2012

9

Example  The factorial of a nonnegative integer is written n! (pronounced n factorial ) and is defined as follows: n!=n(n-1)(n-2)(n-3)……..(n-n)! And 0!=1 For example 5!=5*4*3*2*1*0! which is 120. Draw flowchart and Write a MATALB program that reads nonnegative integer, computes and displays its factorial. 10C10-2 Spring 2012

Flowchart C10-2 Spring OR

12C10-2 Spring 2012