COURSE: BY:HIRA FARMAN. TOPIC: BY:HIRA FARMAN CHAPTER # 04: LET US C & TURBO C.

Slides:



Advertisements
Similar presentations
Selection Feature of C: Decision making statements: It allow us to take decisions as to which code is to be executed next. Since these statements control.
Advertisements

Fundamental of C programming
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
CSCI 130 Advanced Program Control Chapter 8. Program Controls so far for loop while loop do…while loop.
1 Engineering Problem Solving With C++ An Object Based Approach Chapter 3 Control Structures.
1 CIS Jan Overview Selection Statements –If Statement –Else –Nested If-Else –Switch Repetition Statements –While statement –For Statement.
1 CS 192 Lecture 8 Winter 2003 December 17-18, 2003 Dr. Shafay Shamail.
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
The switch Statement, DecimalFormat, and Introduction to Looping
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
Algorithms and Computing Lecture 3 Control Statements By Dr. M. Tahir Khaleeq.
Chapter 4 Program Control Statements
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
Principles of Programming - NI July Chapter 5: Structured Programming In this chapter you will learn about: Sequential structure Selection structure.
1 CSC103: Introduction to Computer and Programming Lecture No 11.
CSEB 114: PRINCIPLE OF PROGRAMMING Chapter 5: Structured Programming.
CPS120 Introduction to Computer Science Iteration (Looping)
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
Additional Control Structures. Chapter 9 Topics Switch Statement for Multi-way Branching Do-While Statement for Looping For Statement for Looping Using.
Previously Repetition Structures While, Do-While, For.
1 Chapter 9 Additional Control Structures Dale/Weems.
1 Additional Control Structures. 2 Chapter 9 Topics  Switch Statement for Multi-way Branching  Do-While Statement for Looping  For Statement for Looping.
1 Do-While Statement Is a looping control structure in which the loop condition is tested after each iteration of the loop. SYNTAX do { Statement } while.
Chapter 7 Additional Control Structures. 2 2 void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response.
Program Flow Control - Looping Addis Ababa Institute of Technology Yared Semu April 2012.
Chapter 3. Outline Relational Operators Loops Decisions Logical Operators Precedence Summary.
Chapter 5: Structured Programming
Conditional Statement Chapter 8. Conditional Statements Are statements that check an expression then may or may not execute a statement or group of statement.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
Chapter 5: Structured Programming
CMSC 104, Lecture 171 More Loops Topics l Counter-Controlled (Definite) Repetition l Event-Controlled (Indefinite) Repetition l for Loops l do-while Loops.
Control Statements in C 1.Decision making statements 2.Looping statements 3.Branching statements
CMP-MX21: Lecture 5 Repetitions Steve Hordley. Overview 1. Repetition using the do-while construct 2. Repetition using the while construct 3. Repetition.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
CMSC 104, Version 9/011 More Loops Topics Counter-Controlled (Definite) Repetition Event-Controlled (Indefinite) Repetition for Loops do-while Loops Choosing.
Loops cause a section of a program to be repeated a certain number of times. The repetition continues while a condition remains true. When a condition.
CS 161 Introduction to Programming and Problem Solving Chapter 18 Control Flow Through C++ Program Herbert G. Mayer, PSU Status 10/8/2014 Initial content.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
We have to discuss following:-  Statements  Statement flow control  Selection statement  Iteration statement.
Control Flow Statements
BY ILTAF MEHDI (MCS, MCSE, CCNA)1. INSTRUCTOR: ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) BY ILTAF MEHDI (MCS, MCSE, CCNA)2 Chapter No: 04 “Loops”
Chapter 2: Fundamental Programming Structures in Java Adapted from MIT AITI Slides Control Structures.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Algorithm & Flow Charts Decision Making and Looping
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
CONTROL FLOW. Introduction  In a program instructions are always executed in the sequential manner.  If programmer wishes to specify the order in which.
Lecture #8 SWITCH STATEMENT By Shahid Naseem (Lecturer)
BY ILTAF MEHDI(MCS,MCSE, CCNA) 1. INSTRUCTOR: ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) BY ILTAF MEHDI(MCS,MCSE, CCNA) 2 Programming Fundamentals Chapter.
Control Structures (Repetition structure) Jump Statements
Chapter 5: Structured Programming
Decision Making in C.
REPETITION CONTROL STRUCTURE
The switch Statement, and Introduction to Looping
Unit-1 Introduction to Java
Decisions Chapter 4.
Statements (6 of 6) A statement causes an action to be performed by the program. It translates directly into one or more executable computer instructions.
Condition Statements.
INC 161 , CPE 100 Computer Programming
CS149D Elements of Computer Science
TOPIC 4: REPETITION CONTROL STRUCTURE
CSC215 Lecture Flow Control.
CSC215 Lecture Control Flow.
Control Structures Part 3
ECE 103 Engineering Programming Chapter 20 Change in Flow of Control
Department of Computer Science
CSC215 Lecture Control Flow.
Presentation transcript:

COURSE: BY:HIRA FARMAN

TOPIC: BY:HIRA FARMAN CHAPTER # 04: LET US C & TURBO C

BY:HIRA FARMAN

 Switch case statements mostly used when we have number of options (or choices) and we may need to perform a different task for each choice.  The control statement that allows us to make a decision from the number of choices is called a switch. BY:HIRA FARMAN

Switch(integer expression) { case constant 1: do this: case constant 2: do this: case constant 3: do this: default: do this; } BY:HIRA FARMAN

main() { int i=2; switch (i) { case 1: printf(“I am in Case1 "); case 2: printf(“I am in Case2 "); case 3: printf(“I am in Case3 "); case 4: printf(“I am in Case4 "); default: printf("Default "); } getch(); } BY:HIRA FARMAN

 Case2 Case3 Case4 Default BY:HIRA FARMAN

The output is definitely not what we expected! we did not expect the second and third line in the previous output. The program prints case 2 & case 3 and the default case. Well, yes,we said the switch executes the case where a match is found and all the subsequent cases and the default as well BY:HIRA FARMAN

 Break statement is used to terminate the execution of a statement block.The next statement which follows this statement block will be executed the keyword is break;  When a break statement is executed in a loop, the repetition of the loop will be terminated.  The break statement is a jump instruction and can be used inside a switch construct, for loop, while loop and do-while loop.  The syntax of a break statement is very simple:  break; BY:HIRA FARMAN

main() { int i=2; switch (i) { case 1: printf(“I am in Case1 "); break; case 2: printf(“I am in break; case 3: printf(“I am in Case3 "); break; case 4: printf(“I am in Case4 "); break; default: printf("Default "); } } BY:HIRA FARMAN

I am in case BY:HIRA FARMAN

Few points about Switch Case BY:HIRA FARMAN

void main() { char ch='b'; switch (ch) { case 'd': printf("CaseD "); break; case 'b': printf("CaseB"); break; case 'c': printf("CaseC"); break; case 'z': printf("CaseZ "); break; default: printf("Default "); } getch(); } BY:HIRA FARMAN

 CaseB BY:HIRA FARMAN

main() { int i=1; switch(i-2) { case -1; printf(“\nfeeling great”); break; case 0: printf(“\n feeling happy”); break; case 1: printf(“\feeling excited”); break; default: printf(“felling sad because default condition"); } getch(); } BY:HIRA FARMAN

 feeling great BY:HIRA FARMAN

Write a program to accept day no(1 to 7) and print the day name. BY:HIRA FARMAN

 Avoid goto keyword!They make a C programmer’s life miserable. There is seldom a legitimate reason for using goto and use is one of the reasons that programs become unreliable, unreadable,& hard to debug.And yet many programmers find goto. BY:HIRA FARMAN

 In a difficult programming situation,it seems so easy to use a goto to take control where u want. BY:HIRA FARMAN

 The big problem with goto’s is that when we do use them we can never be sure how we got a certain point in our code. They obscure the flow of control.(so as far as possible skip them)you can always get the job done without them. BY:HIRA FARMAN

main() { int goals; printf(“Enter the number of goals scored against India\n”); If(goals<=5) goto ter; else { printf(“About time soccer players learnt C\n”); printf(“and said goodbye!); } ter: printf(“data jump”); getch(); } BY:HIRA FARMAN

Enter the number of goals scored against India 3 data jump (But) Enter the number of goals scored against India 7 About time soccer players learnt C and said goodbye BY:HIRA FARMAN

QUESTIONS & ANSWERS??? BY:HIRA FARMAN

QNO1:Using goto keyword make any program. QNO2:Using switch statement make a program on your choice. (it should be different from lecture) BY:HIRA FARMAN