Presentation is loading. Please wait.

Presentation is loading. Please wait.

Announcements Exam 1 Grades Posted on blackboard Average: 83.26

Similar presentations


Presentation on theme: "Announcements Exam 1 Grades Posted on blackboard Average: 83.26"— Presentation transcript:

1 Announcements Exam 1 Grades Posted on blackboard Average: 83.26
Median: 86 High: (4)

2 Iteration Iteration (Looping): Performing a Series of Statements Multiple Times until Some Condition Is Met. Eliminates the Need for Redundant Coding or Function Calls

3 The while Loop Syntax: while condition statement; end

4 while Example MAX = 100; counter = 0; while counter < MAX
disp(counter); counter = counter + 1; end

5 Example while Loop numEmployees = input('Enter Number of Employees: '); if numEmployees > 0 curNum = 0; while curNum < numEmployees disp('Welcome to CorpLand!'); curNum = curNum + 1; end %while end %if

6 Example while Loop numEmployees = input('Enter Number of Employees: '); if numEmployees > 0 curNum = 0; while curNum < numEmployees disp('Welcome to CorpLand!'); curNum = curNum + 1; end %while end %if

7 The for Loop Syntax: Same as:
for starting assignment:step: terminating value statement end Same as: starting assignment; while variable <= terminating value variable = variable + step;

8 Example for Loop numEmployees = input('Enter Number of Employees: ');
if numEmployees > 0 for curNum = 1:1:numEmployees disp('Welcome to CorpLand!'); end else disp('Hmmmmm!!!');

9 Example for Loop numEmployees = input('Enter Number of Employees: ');
if numEmployees > 0 for curNum = 1:numEmployees %step assumed to be 1 disp('Welcome to CorpLand!'); end else disp('Hmmmmm!!!');

10 Looping for Input stringEntered = 'go';
while ~strcmp(stringEntered,'stop') stringEntered = input('Enter a string: ','s'); end

11 Nested Loops for k = 1 : 10 for l = 1 : 10
out1 = sprintf('%d%d ',k,l); disp(out1); end

12 Quiz 2 Need to Know : Loops : while , for No Terminology on Quiz 2


Download ppt "Announcements Exam 1 Grades Posted on blackboard Average: 83.26"

Similar presentations


Ads by Google