Statements

Slides:



Advertisements
Similar presentations
Java Control Statements
Advertisements

Control Statements. Define the way of flow in which the program statements should take place. Control Statements Implement decisions and repetitions.
Fundamental of C programming
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
LOOP / REPETITION while loop. for loop do/while loop We assume that loops are not meant to be infinite. That is, there should always be a way out of the.
Topic 03 Control Statements Programming II/A CMC2522 / CIM2561 Bavy Li.
1 Lecture 11:Control Structures II (Repetition) (cont.) Introduction to Computer Science Spring 2006.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
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.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
1 Lecture 14 Chapter 6 Looping Dale/Weems/Headington.
CLASS XI By Sumita Arora
UNIT II Decision Making And Branching Decision Making And Looping
CHAPTER 5 CONTROL STRUCTURES II (Repetition). In this chapter, you will:  Learn about repetition (looping) control structures  Explore how to construct.
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
Chapter 4: Control Structures II
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
Computer Science Department Relational Operators And Decisions.
DiagrammaticRepresentation Iteration Construct False True Condition Exit from Statement (s) loop Sequence construct Selection construct Statement 1 Statement.
Selection Structures (if & switch statements) (CS1123)
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II UTPA – Fall
CONTROLLING PROGRAM FLOW
1 Chapter 9 Additional Control Structures Dale/Weems.
Switch Statement Is a selection control structure for multi-way branching. SYNTAX switch ( IntegralExpression ) { case Constant1 : Statement(s); // optional.
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.
Chapter 5 Loops. Overview u Loop Statement Syntax  Loop Statement Structure: while, for, do-while u Count-Controlled Loops u Nested Loops u Loop Testing.
C++ for Engineers and Scientists, Third Edition1 Objectives In this chapter, you will learn about: Basic loop structures while loops Interactive while.
Computer Science Department LOOPS. Computer Science Department Loops Loops Cause a section of your program to be repeated a certain number of times. The.
OBJECTIVES  Illustration of the Concept of Control Flow  Types of Control Flow  Knowledge about conditional and repetitive statements.  Make more.
Program Flow Control - Looping Addis Ababa Institute of Technology Yared Semu April 2012.
Chapter 3. Outline Relational Operators Loops Decisions Logical Operators Precedence Summary.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Control structures Algorithm Development Conditional Expressions Selection Statements 1.
Looping Construct or Statements. Introduction of looping constructs In looping,a sequence of statements are executed until some condition for termination.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Decision Making It is used to change the order of the program based on condition. Categories: – Sequential structure – Selection structure – Iteration.
Control of flow We learned that default flow of instructions is sequential. Then, we learned how to control the flow using "if" and "switch." Now, we will.
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
Repetition Statements (Loops) The do while Loop The last iteration structure in C++ is the do while loop. A do while loop repeats a statement or.
Chapter : 9 Control Statements Control Flow: A control flow Statement regulates the order in which statements get executed. F Flow-order in which the computer.
We have to discuss following:-  Statements  Statement flow control  Selection statement  Iteration statement.
CSI 3125, Preliminaries, page 1 Control Statements.
LESSON 4 Decision Control Structure. Decision Control Structures 1. if statement 2. if-else statement 3. If-else-if statement 4. nested if statement 5.
COMP Loop Statements Yi Hong May 21, 2015.
Course Title Object Oriented Programming with C++ Course instructor ADEEL ANJUM Chapter No: 04 loops 1 BY ADEEL ANJUM ( MSc - cs, CCNA, WEB DEVELOPER )
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
Lecture 7 Computer Programming -1-. Conditional Statements 1- if Statement. 2- if ….. else Statement. 3- switch.
FLOW OF CONTROL In C++ the program execution starts with the first statement in the main() and ends with the last statement of main(). This is called.
Chapter 4 Repetition Statements Program Development and Design Using C++, Third Edition.
CONTENTS Loop Statements Parts of a loop Types of Loops Nested Loops
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.
 By the end of this section you should be able to: ◦ Differentiate between sequence, selection, and repetition structure. ◦ Differentiae between single,
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
Computer Programming -1-
LESSON 4 Decision Control Structure
Decisions Chapter 4.
Intro to Programming Week # 4 Switch Statement Lecture # 7
Chapter 2.2 Control Structures (Iteration)
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
IF if (condition) { Process… }
Chapter 2.2 Control Structures (Iteration)
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.
ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Department of Computer Science
Programming Fundamental
Programming Fundamental
Presentation transcript:

Statements

Statement 1 Statement 2 Statement 3

Respective statements If condition is false If condition is false Condition ? Respective statements If condition is true If condition is true

Condition ? Condition ? Statement 1 Statement 2 The exit condition false The loop body true

‘if’ is called single selection structure because it select or ignore a single action. Syntax(general form):- if(condition) { c++ expression or statement ; }

A nested if is an if that has another if in its if’s body or in its else’s body. Syntax :- If(condition ) { c++ expression ; } if(condition ) { c++ expression ; } else { C++ expression ; } else { C++ expression ; } If(condition ) { c++ expression ; } if(condition ) { c++ expression ; } else { C++ expression ; } else { C++ expression ; }

Void main() { int age; Cout<<”Enter the age”; Cin>>age; If (age>=60) { Cout<<”Eligible”; }.else { Cout<<“Not”; }. getch (); } Examples of Selection Statement #include Void main() { int grade; Cout<<”Enter the grade”; Cin>>grade; If (grade>=60) { Cout<<”pass”; }. getch () } #include

Void main() { float a,b,Result; Char ch; Cout<<”Enter the number 1:”; Cout<<”Enter the number 2:”; Cin>>a>>b; Cin>>ch;.. if (ch==‘-’) Result=a-b;.else if (ch==‘+’) Result=a+b;.. else { Cout<<“Wrong entry”; } Cout<<Result;. getch (); } #include Void main() { int grade; Cout<<”Enter the grade in marks:”; Cin>>grade; switch (grade) { Case 90 :cout<<“A”; break; Case 80:cout<<“A”; break; Case 70 :cout<<“A”; break; Case 50 :cout<<“A”; break; Case 40 :cout<<“A”; break; default; } Cout<< “Wrong Entry”;. getch (); } #include Ex. Of Nested if Ex. Of Switch

The iteration statement allows a set of instruction to be perform repeatedly until a certain condition is felled. It is also known as Loop’s. Loops are of four types that is:

Examples of For and Nested Loop Void main() { int i;.. for (i =10;i<=10;i++) { Cout<<“\n”<<i; }. getch (); } #include Void main() { int i,j;.. for (i =1;i<5;i++) Cout<<“\n”; for (j=1;j<i; j++) Cout<<“*”;. getch (); } #include

Void main() { int i=1;.. while (i<=10) { cout<<i; } i++;. getch (); } #include Void main() { int i=1; do { cout<<i; } i++; while(i<=10). getch (); } #include Example of while and do-while loop