{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture06

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

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

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

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

View Full Document
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
CS107, Prof. Steinberg, S10 3 Lecture 06 If if boolean expression Do one set of statements statements elseif boolean expression statements else statements end Do statements corresponding to first true expression If none true, do this. If there is no else, do nothing

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

View Full Document
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
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

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

View Full Document
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
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

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

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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern