EGR_102_Lab_10A_Iterative_Programming_II

EGR_102_Lab_10A_Iterative_Programming_II - EGR 102 Lab 10A...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: EGR 102 Lab 10A 1 Iterative Programming II EGR 102 Lab 10A 2 Structured Programming Two types of statements that allow programs to take non-sequential paths: Conditional Programming (Selection) Branches the flow based on a decision Iterative Programming (Repetition) Loops the flow to allow statements to be repeated EGR 102 Lab 10A 3 Iterative Programming Loops perform operations repetitively. The number of iterations is dependant on the type of loop. EGR 102 Lab 10A 4 Iterative Programming Two types of MATLAB loop structures: for structure Loop ends after a specified number of repetitions while structure Loop ends when a logical condition is satisfied This type of programming only used inside user-defined functions and scripts (M-files) EGR 102 Lab 10A 5 while Structure Repeats the same set of commands as long as a logical condition remains true General syntax of while loop: while condition statements end condition is a logical expression that is either true or false statements are the commands to be repeated as long as the condition is TRUE EGR 102 Lab 10A 6 while Structure General syntax of while loop: while condition statements end The variable in the condition expression: 1. Must be defined before the loop 2. Must be recalculated within the loop Unlike the for loop, user does not know how many times the while loop will repeat EGR 102 Lab 10A 7 while Structure Simple Examples: x = 8 while x > 0 x = x 3 end This will display x = 8, 5, 2, -1 in succession Because x is the variable in the...
View Full Document

Page1 / 8

EGR_102_Lab_10A_Iterative_Programming_II - EGR 102 Lab 10A...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online