EGR_102_Lab_10B_Nested_Programming_I

# EGR_102_Lab_10B_Nested_Programming_I - EGR 102 Lab 10B 1...

This preview shows pages 1–4. Sign up to view the full content.

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: EGR 102 Lab 10B 1 Nested Programming I EGR 102 Lab 10B 2 Structured Programming Conditional Programming (Selection) Branches the flow based on a decision if condition statements end if condition statements 1 else statements 2 end if condition 1 statements 1 elseif condition 2 statements 2 elseif condition 3 statements 3 else statements n end EGR 102 Lab 10B 3 Structured Programming Iterative Programming (Repetition) Loops the flow to allow statements to be repeated for index = values statements end while condition statements end EGR 102 Lab 10B 4 Nested Programming Can combine different and similar types of programming structures Separate structures can be nested within each other This type of programming only used inside user-defined functions and scripts (M-files) EGR 102 Lab 10B 5 Nested Programming Nesting multiple if statements Provide for various decisions and sub-decisions Most useful when results fall into several sub-categories within two or more major categories EGR 102 Lab 10B 6 Nested if statements if a == 0 if b == 0 error( 'Trivial solution' ); else display( 'Single root' ) roots = -c/b; end else d = b^2 - 4*a*c; r1 = (-b + sqrt(d))/(2*a); r2 = (-b - sqrt(d))/(2*a); if d >= 0 display( 'Two real roots' ) else display( 'Two complex roots' ) end roots = [r1,r2]; end input a, b, c calculate...
View Full Document

{[ snackBarMessage ]}

### Page1 / 8

EGR_102_Lab_10B_Nested_Programming_I - EGR 102 Lab 10B 1...

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

View Full Document
Ask a homework question - tutors are online