Control Statements in C. C Keywords autodoubleintstruct breakelselongswitch caseenumregistertypedef charexternreturnunion constfloatshortunsigned continueforsignedvoid.

Slides:



Advertisements
Similar presentations
INTEC CS160 - Jeanine Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 3 Control Structures and Data Files.
Advertisements

Java Control Statements
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.
Control Statements. Define the way of flow in which the program statements should take place. Control Statements Implement decisions and repetitions.
1 Conditional Statement. 2 Conditional Statements Allow different sets of instructions to be executed depending on truth or falsity of a logical condition.
For loops For loops are controlled by a counter variable. for( c =init_value;c
Unit 2 The if-else-if LECTURE – 14
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman Chapter 4 (Conditional Statements) © CPCS
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Control Structures for Loops.
Understanding Loops Using C Language Week 15 Mr.Omer Salih.
CS Data Structures Appendix 1 How to transfer a simple loop- expression to a recursive function (factorial calculation)
Lecture 02 Data Types, Conversions if Statements METU Dept. of Computer Eng. Summer 2002 Ceng230 - Section 01 Introduction To C Programming by Ahmet Sacan.
Programming Control Flow. Sequential Program S1 S2 S5 S4 S3 int main() { Statement1; Statement2; … StatementN; } Start End.
If () else statement, switch statement, while () loop, do…while() loop and for( ; ; ) loop 1.
Arrays, Conditionals & Loops in Java. Arrays in Java Arrays in Java, are a way to store collections of items into a single unit. The array has some number.
CONTROL STATEMENTS Lakhbir Singh(Lect.IT) S.R.S.G.P.C.G. Ludhiana.
Programming C for Engineers An exercise is posted on the web site! Due in one week Single submission.
Lecture 10: Reviews. Control Structures All C programs written in term of 3 control structures Sequence structures Programs executed sequentially by default.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
1 Conditional Statement. 2 Conditional Statements Allow different sets of instructions to be executed depending on truth or falsity of a logical condition.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
C Programming Lecture 7 : Control Structures. Control Structures Conditional statement : if, switch Determine a block of statements to execute depending.
Lecture 2 Control Structure. Relational Operators -- From the previous lecture Relational Operator Meaning == is equal to < is less than > is greater.
Control Statements in C 1.Decision making statements 2.Looping statements 3.Branching statements
Week 6: Functions - Part 2 BJ Furman 01OCT2012. The Plan for Today Comments on midterm exam (next week in lab!) Review of functions Scope of identifiers.
Lecture 2, basic C. Michigan State University CSE 251,Spring 2009 Getting Started Log in using diskless (if you’re on Windows) Make sure you know how.
Lecture 10: Modular Programming (functions) B Burlingame 13 April 2015.
THE C PROGRAM WORKSHOP. Workshop Features Door for expected results to go out Door for requests to go in Door for unexpected results to go out Bins for.
Topics to be covered  Introduction to C Introduction to C  Characterstics of C Characterstics of C  Characterset Characterset  Keywords Keywords 
/* example program to demonstrate the passing of an array */ #include int maximum( int [] ); /* ANSI function prototype */ int maximum(
1 Agenda If Statement True/False Logical Operators Nested If / Switch Exercises & Misc.
Repetition Repetition allows you to repeat an operation or a series of operations many times. This is called looping and is one of the basic structured.
CSI 3125, Preliminaries, page 1 Control Statements.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
Introduction to Software Design. Yes Make Modifications Inception Analysis Specification Design Programming Testing Use Program Errors? Fulfills User.
Agenda  Basic Logic - Continued...  if else statements  switch Statements  Compound Conditions.
Control structures in C by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
6. LOOPS. Example: Summing a Series of Numbers #include int main(void) { int n, sum = 0; printf("This program sums a series of numbers.\n"); printf("Enter.
Conditionals. Conditional Execution A conditional statement allows the computer to choose an execution path depending on the value of a variable or expression.
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
CHAPTER#3 STRUCTURED PROGRAM DEVELOPMENT IN C 1 A.AlOsaimi King Saud University College of Applied studies and Community Service Csc 1101.
Lecture 7: Variable Scope B Burlingame March 16, 2016.
 Real numbers representation - Floating Point Notation  First C Program  Variables Declaration  Data Types in C ◦ char, short, int, long, float, double,
Module 6 – Decision Control Statements Objectives  Understands Increment/Decrement operators, Conditional and special operators in C  Understands significance.
Flow Control. Comments u Comments: /* This is a comment */ –Use them! –Comments should explain: v special cases v the use of functions (parameters, return.
Basics of ‘ C ’ By Gaikwad Varsha P. Asst. Prof. Information Technology Dept. Govt. College of Engg. Aurangabad.
Tutorial #4 Summer 2005.
Control Statements in C
Course Outcomes of Programming In C (PIC) (17212, C203):
Unit-1 Introduction to Java
Decisions Chapter 4.
EKT150 INTRODUCTION TO COMPUTER PROGRAMMING
Chapter 4 (Conditional Statements)
CS1010 Programming Methodology
Iteration statement while do-while
INC 161 , CPE 100 Computer Programming
Looping.
CS149D Elements of Computer Science
Chapter 13 Control Structures
CSC215 Lecture Control Flow.
Control structures Chapter 3.
Relational, Logical, and Equality Operators
Control structures Chapter 3.
Program Flow.
Control structures Chapter 3.
Department of Computer Science
CSC215 Lecture Control Flow.
CSCE 206 Lab Structured Programming in C
Chapter 13 Control Structures
Control Structure គោលបំណងនៃមេរៀន អ្វីជា Control structure ?
Presentation transcript:

Control Statements in C

C Keywords autodoubleintstruct breakelselongswitch caseenumregistertypedef charexternreturnunion constfloatshortunsigned continueforsignedvoid defaultgotosizeofvolatile doifstaticwhile The words in bold print are used in control statements. They change the otherwise sequential execution of the assignment statements in a function block

assignment statement aResult = 10; aResult = countB; aResult = (aValue + 100) / countD; aResult = sqrt (aValue);

block of statements { const int MAX_BINS = 11; int orderNumber; int binNumber; printf("Enter order number: "); scanf("%d", &orderNumber); binNumber = orderNumber % MAX_BINS; printf("Bin number is %d\n", binNumber); }

simple “if” statement if (aNumber != 1000) countA++;

“if” with a block of statements if (aValue <= 10) { printf("Answer is %8.2f\n", aValue); countB++; } // End if

“if” – “else” with a block of statements if (aValue <= 10) { printf("Answer is %8.2f\n", aValue); countB++; } // End if else { printf("Error occurred\n"); countC++; } // End else

nested “if” statement if (aValue == 1) countA++; else if (aValue == 10) countB++; else if (aValue == 100) countC++; else countD++;

“while” with a single statement while (aResult >= 1000) aResult = aResult / aValue;

“while” with a block of statements while (aResult >= 1000) { aResult = aResult / aValue; printf("Result is %9.4f\n", aResult); } // End while

“while” with nested “if” statements aResult = MAX_VALUE; while (aResult >= 1000) { countW++; // nested if statement if (aValue == 1) countA++; else if (aValue == 10) countB++; else if (aValue == 100) countC++; else countD++; aResult = aResult / aValue; } // End while

“while” performing an infinite loop while (1) { receiveFrom (aClient, aRequest); theResults = processRequest(aRequest); sendTo (aClient, theResults); } // End while

“for” with a single statement for (i = 1; i <= MAX_LENGTH; i++) printf("#");

“for” with a block of statements for (i = 0; i < MAX_SIZE; i++) { printf("Symbol is %c\n", aBuffer[i]); aResult = aResult / i; } // End for

“for” performing an infinite loop for (;;) { receiveFrom (client, request); results = processRequest(request); sendTo (client, Results); } // End for

“switch” statement switch (aNumber) { case 1 : countA++; break; case 10 : countB++; break; case 100 : case 500 : countC++; break; default : countD++; } // End switch