lecture07

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

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

View Full Document Right Arrow Icon
CS107, Prof. Steinberg, S12 1 Lecture 07 CS107: Computing for Math CS107: Computing for Math and Science and Science Lecture 07: Input / Output Loops
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
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
Background image of page 7

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

View Full DocumentRight Arrow Icon
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 else end end
Background image of page 8
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
Background image of page 9

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

View Full DocumentRight Arrow Icon
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
Background image of page 10
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
Background image of page 11

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

View Full DocumentRight Arrow Icon
CS107, Prof. Steinberg, S12
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 56

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

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

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