Lecture14 Conditional Execution 2

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

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

View Full Document Right Arrow Icon
FAST, National University of Computer and Emerging Sciences, Islamabad 1 Lecture 14:  Conditional Execution-II Course: Programming For Engineers-1 Asma Ahmad
Image of page 1

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

View Full Document Right Arrow Icon
Contents If selection statement If else selection statement 2
Image of page 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.
Image of page 3

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

View Full Document Right Arrow Icon
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.
Image of page 4
If statement If-else statement Nested If-else statement Switch Statement Conditional Operator
Image of page 5

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

View Full Document Right Arrow Icon
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'.
Image of page 6
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
Image of page 7

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

View Full Document Right Arrow Icon
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”
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern