Department of Computer Science

Slides:



Advertisements
Similar presentations
Control Flow Statements: Repetition/Looping
Advertisements

Algorithm & Flow Charts Decision Making and Looping Presented By Manesh T Course:1090 CS.
Unit 2 The if-else-if LECTURE – 14
Iteration This week we will learn how to use iteration in C++ Iteration is the repetition of a statement or block of statements in a program. C++ has three.
1 MATERI PENDUKUNG JUMP Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
ספטמבר 04Copyright Meir Kalech1 C programming Language Chapter 2: Control Flow.
CONTROL STATEMENTS Lakhbir Singh(Lect.IT) S.R.S.G.P.C.G. Ludhiana.
UNIT II Decision Making And Branching Decision Making And 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.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee C Language Part 2.
CPS120: Introduction to Computer Science Decision Making in Programs.
Chapter 5 Control Structures: Loops 5.1 The while Loop The while loop is probably the most frequently used loop construct. The while loop is a conditional.
DiagrammaticRepresentation Iteration Construct False True Condition Exit from Statement (s) loop Sequence construct Selection construct Statement 1 Statement.
CPS120 Introduction to Computer Science Iteration (Looping)
Programming Fundamentals Lecture 4. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output.
1 Flowchart notation and loops Implementation of loops in C –while loops –do-while loops –for loops Auxiliary Statements used inside the loops –break –continue.
Control Statements (Decision Making)
Program Flow Control - Looping Addis Ababa Institute of Technology Yared Semu April 2012.
Chapter 3. Outline Relational Operators Loops Decisions Logical Operators Precedence Summary.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
Decision making statements. Decision making statements are used to skip or to execute a group of statements based on the result of some condition. The.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Looping Construct or Statements. Introduction of looping constructs In looping,a sequence of statements are executed until some condition for termination.
Iterations Very Useful: Ability to repeat a block of code Example:
Decision Making It is used to change the order of the program based on condition. Categories: – Sequential structure – Selection structure – Iteration.
CPS120 Introduction to Computer Science Iteration (Looping)
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.
Statements
CPS120: Introduction to Computer Science Decision Making in Programs.
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.
For Loop Lecture No 8. Definition In computer science a for loop is a programming language statement which allows code to be repeatedly executed. A for.
Asstt. Prof Mandeep Kaur Computer Dept. TOPIC: Control Statements in C language.
Control Flow Statements
CSI 3125, Preliminaries, page 1 Control Statements.
CPS120: Introduction to Computer Science Decision Making in Programs.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Control structures in C by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
CONTENTS Loop Statements Parts of a loop Types of Loops Nested Loops
Algorithm & Flow Charts Decision Making and Looping
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
CSC COMPUTER EDUCATION, M.K.B.NAGAR CHAPTER 3. CSC COMPUTER EDUCATION, M.K.B.NAGAR Session Objectives Explain If, If..else statements Understand Looping.
The following statements are for y = -1; if ( x ) if ( x>0 ) y = 1; else y = 0; A. y= -1 x0 B. y= 0 x0 C. y= 1 x
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
Control Structures Introduction
‘C’ Programming Khalid Jamal.
Course Outcomes of Programming In C (PIC) (17212, C203):
Chapter 6: Loops.
REPETITION CONTROL STRUCTURE
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.
Quick Test What do you mean by pre-test and post-test loops in C?
CiS 260: App Dev I Chapter 4: Control Structures II.
Control Structures.
Flow of Control.
FLOW OF CONTROL.
Flow of Control.
IF if (condition) { Process… }
Chapter 6 Decision Making and Looping
Flow of Control.
CSC215 Lecture Flow Control.
CSC215 Lecture Control Flow.
Lab5 PROGRAMMING 1 Loop chapter4.
Conditionals.
By Hector M Lugo-Cordero September 3, 2008
Program Flow.
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
Introduction to Computer Science
CSC215 Lecture Control Flow.
Presentation transcript:

Department of Computer Science CONTROL STATEMENTS B. Anuradha Department of Computer Science II Sem, Programming in C IN ‘C’

Decision control statement Iteration statement Transfer statement

Decision control statement it alter the sequential execution of the statement of the program depending on the test condition in program Types of Decision control statement:- If statement Decision control statement If else statement Switch statement Go To statement

The If statement: It is a powerful decision making statement and is used to control the flow of execution of statement. FALSE condition TRUE Block of if Next statement STOP

main() { int a; printf(“enter value of a”); scanf(“%d”,&a); if(a>25) { } printf(“no.is greater than 25”); printf(“\n bye”); getch(); }

If else statement: If the condition is true the true block is execute otherwise False block is execute. FALSE condition TRUE Block of if Block of else Next statement STOP

main() { int n,c; printf(“\n enter value of n”); scanf(“%d”,&n); c=n%2; if(c==0) printf(“no is even”); else printf(“no is odd”); getch(); }

Syntax Of Else If Leader: What Is Else If Ladder: If we are having different - different test conditions with different - different statements, then for these kind of programming we need else if ladder Syntax Of Else If Leader: --------------------------------------------------------------------- if(test_condition1) { statement 1; } else if(test_condition2) statement 2; else if(test_condition3) statement 3; else if(test_condition4) statement 4; else

switch statement it selects one of the several alternatives.

A GO TO statement can cause program control to end up anywhere in the program unconditionally. Example main() { int i=1; Up printf(“Hello To C”) i++; If (i<=5) goto upgetch(); }

Iteration or looping statement: Depending on the position of control statement in c,control structure may be classified Entry_ controlled loop Exit _controlled loop

False True Entry controlled loop Exit controlled loop Test conditio n ? True Body of the loop Body of the loop Test conditio n ? Entry controlled loop Exit controlled loop

While statement Do statements for statements C language provides three constructs for perfoming loop operations While statement Do statements for statements

While(test condition) While statement While(test condition) { body of the loop }

While(test condition) Do While statement do { Body of the loop } While(test condition)

for loop statement: Intialization of control variable The value of control variable tested using test condition If the condition is true ,the body of loop executed,otherwise terminated

int_sum=0; for(int_n=1;int_n<=10;int_n++) { int_sum=int_sum+int_n; } printf(“sum=%d\n”,int_sum);

Nesting of for loop For(i=0;i<n;i++) { ……………………………… For(j=0;j<n-1;j++) ……………………………… }

while(test condition) { …………………………….. ……………………………… if(condition) Jumping out of a loop Exit from a loop using break statement ie break will exit only a single loop Eg: while(test condition) { …………………………….. ……………………………… if(condition) break;

Skipping a part of loop Another statement ‘continue’, It tells the compiler skip the following statements and continue with next iteration Eg: While (test condition) { ……………………….. If(…………) Continue;