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