{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

L4_control_stud

# L4_control_stud - CGN 3421 Computer Methods Gurley Lecture...

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

CGN 3421 - Computer Methods Gurley Lecture 4 - Control Structures page 18 of 26 Lecture 4 - Control Structures Three ways to control the flow of a program if - end decision (no loop) if (condition1 true) needed statements elseif (condition2 true) optional statements else optional statemetns end needed for - end counted loop (repeat statements, no decision) for variable = start : increment : stop statements inside counted loop end while - end conditional loop (repeat statements and make a decision) while (condition true) statements inside conditional loop end

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

View Full Document
CGN 3421 - Computer Methods Gurley Lecture 4 - Control Structures page 19 of 26 if - end decision (no loop) >> if ( condition 1 ) >> execute statement(s) >> elseif ( condition 2 ) >> execute statement(s) >> elseif ( condition 3 ) >> execute statement(s) >> else >> execute statement(s) >> end >> ... rest of the program decision structure will find only one condition true when one condition is found true, all other conditions are ignored condition 1 condition 2 condition 3 anything else
CGN 3421 - Computer Methods Gurley Lecture 4 - Control Structures page 20 of 26 Example #1: grades >> grade = input(‘enter student grade ’) >> if (grade >= 90) >> letter = ‘A’ >> elseif (grade >= 80) >> letter = ‘B’ >> elseif (grade >= 70) >> letter = ‘C’ >> else >> letter = ‘D or F’ >> end decision structure will execute only one letter assignment when one condition is found true, all other conditions are ignored grade >= 90 grades < 70 80 > grade >= 70 90 > grade >= 80

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

View Full Document
CGN 3421 - Computer Methods Gurley Lecture 4 - Control Structures page 21 of 26 example #2: grades (logic error) >> grade = input(‘enter student grade ’) >> if (grade >= 70) >> letter = ‘C’ >>
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