lecture06 - CS107: Computing for Math and Science Click to...

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

View Full Document Right Arrow Icon
CS107, Prof. Steinberg, S10 1 Lecture 06 Click to edit Master subtitle style CS107: Computing for Math and Science Lecture 06: IF and Nested IF
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, S10 2 Lecture 06 If if boolean expression statements elseif boolean expression statements else statements end Evaluate these one by one until find first one that is true
Background image of page 2
CS107, Prof. Steinberg, S10 3 Lecture 06 If if boolean expression Do one set of statements statements elseif statements else statements end Do statements corresponding to first true expression If none true, do this. If there is no else, do nothing
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, S10 4 Lecture 06 Example Under what conditions would this print yes? No? if (x > 0) disp(‘no’) else disp(‘yes’) end
Background image of page 4
CS107, Prof. Steinberg, S10 5 Lecture 06 Example Under what conditions would this print yes? if (x > 0) disp(‘no’) elseif (y < 0) disp(‘maybe’) else disp (‘yes’) 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, S10 6 Lecture 06 Testing Ifs Test data should execute every line of code Test data should make every if “barely true” and “barely false” E.g., x > 5, x an integer Barely true: x = 6 Barely false: x = 5 E.g., x > 5, x a real number Barely true: 5.00001 Barely false: x = 5
Background image of page 6
CS107, Prof. Steinberg, S10 7 Lecture 06 Barely true/false X X > 5 3 0 4 0 5 0 6 1 7 1 Last false First true
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, S10 8 Lecture 06
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 30

lecture06 - CS107: Computing for Math and Science Click to...

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

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