{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture07

lecture07 - CS107 Computing for Math and Science Lecture 07...

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

CS107, Prof. Steinberg, S12 1 Lecture 07 CS107: Computing for Math CS107: Computing for Math and Science and Science Lecture 07: Input / Output Loops

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

View Full Document
CS107, Prof. Steinberg, S12 2 Lecture 07 Midterm Exam 1 Midterm Exam 1 Tuesday, February 21 two weeks from tonight Pharmacy 111, 5:00 - 6:20 PM Normal lecture time and place Closed book, closed notes, bring ID Watch Sakai for Full rules Practice exam Topic list
CS107, Prof. Steinberg, S12 3 Lecture 07 Review: If Review: If Syntax: if boolean expr 1 statements 1 elseif boolean expr 2 statements 2 0 or more elseif boolean expr i statements i else 0 or 1 statements i+1 end

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

View Full Document
CS107, Prof. Steinberg, S12 4 Lecture 07 else if vs else if vs elseif elseif elseif continues the current if-elseif-else- end else if is like else if It starts a new, nested if structure which needs its own end
CS107, Prof. Steinberg, S12 5 Lecture 07 Example of Example of elseif elseif vs else if vs else if if length > 40 res = ‘too long’; elseif weight > 20 res = ‘too heavy’; else res = ‘ok’; end if length > 40 res = ‘too long’; else if weight > 20 res = ‘too heavy’; else res = ‘ok’; end end

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

View Full Document
CS107, Prof. Steinberg, S12 6 Lecture 07 if length > 40 res = ‘too long’; elseif weight > 20 res = ‘too heavy’; else res = ‘ok’; end if length > 40 res = ‘too long’; else if weight > 20 res = ‘too heavy’; else res = ‘ok’; end end
CS107, Prof. Steinberg, S12 7 Lecture 07 elseif elseif , else, end -> if , else, end -> if if length > 40 res = ‘too long’; elseif weight > 20 res = ‘too heavy’; else res = ‘ok’; end if length > 40 res = ‘too long’; else if weight > 20 res = ‘too heavy’; else res = ‘ok’; end end

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

View Full Document
CS107, Prof. Steinberg, S12 8 Lecture 07 if length > 40 res = ‘too long’; elseif weight > 20 res = ‘too heavy’; else res = ‘ok’; end if length > 40 res = ‘too long’; else if weight > 20 res = ‘too heavy’; else end end
CS107, Prof. Steinberg, S12 9 Lecture 07 Review: Writing nested ifs Review: Writing nested ifs Magazine subscription: 1 year: \$12 print, \$10 online 2 years: \$20 print, \$18 online 3 years: \$28 print, \$26 online Variables: years: integer, number of years online: boolean, true means online, false means print cost: integer, number of dollars

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

View Full Document
CS107, Prof. Steinberg, S12 10 Lecture 07 Writing nested ifs Writing nested ifs Choose a variable and write test(s): Number of years if years = = 1 years holds 1 elseif years = = 2 years holds 2 else years holds 3 end
CS107, Prof. Steinberg, S12 11 Lecture 07 Writing nested ifs Writing nested ifs Focus on one case if years = = 1 years holds 1 elseif years = = 2 years holds 2 else years holds 3 end

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

View Full Document
CS107, Prof. Steinberg, S12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 56

lecture07 - CS107 Computing for Math and Science Lecture 07...

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

View Full Document
Ask a homework question - tutors are online