Lecture14 Conditional Execution 2

# Lecture14 Conditional Execution 2 - Lecture14: Course:...

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

FAST, National University of Computer and Emerging Sciences, Islamabad 1 Lecture 14:  Conditional Execution-II Course: Programming For Engineers-1 Asma Ahmad

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

View Full Document
Contents If selection statement If else selection statement 2
Need In every day life, we often making decisions. For example, the statement ‘if the shop is open, bring one kg of sugar while returning home from college’, involves this phenomenon. Thus we are making a decision on the condition that the shop is open.

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

View Full Document
More Examples The college gives admission to a student if he has the required percentage in his previous examination and/or in the entry test. Similarly administration of a basketball team of the college decides that the students having height more than six feet can be members of the team.
If statement If-else statement Nested If-else statement Switch Statement Conditional Operator

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

View Full Document
1. if statement Every programming language provides a structure for decision making. 'C' also provides this structure. The statement used for decisions in 'C' language is known as the ' if statement'.
7 The  if  Selection Statement Selection structure: Used to choose among alternative courses of action Pseudocode: If student’s grade is greater than or equal to 60 Print “Passed” If condition true Print statement executed and program goes on to next statement If false , print statement is ignored and the program goes onto the next statement Indenting makes programs easier to read C ignores whitespace characters

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

View Full Document
8 The  if  Selection Statement Pseudocode statement in C: if ( grade >= 60 )     printf( "Passed\n" );  C code corresponds closely to the pseudocode if ( grade >= 60 )  {    printf( "Passed\n" );  } true false grade >= 60 print “Passed”
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