Unary Not operator !  !true = false  !false = true.

Slides:



Advertisements
Similar presentations
Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.
Advertisements

Introduction to Programming Lecture 5. In the Previous Lecture Basic structure of C program Basic structure of C program Variables and Data types Variables.
If Statements & Relational Operators Programming.
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
Introduction to working with Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
1 Lecture 11:Control Structures II (Repetition) (cont.) Introduction to Computer Science Spring 2006.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
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.
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
Loops – While, Do, For Repetition Statements Introduction to Arrays
1 Lecture 14 Chapter 6 Looping Dale/Weems/Headington.
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
What is the out put #include using namespace std; void main() { int i; for(i=1;i
Loops Programming. COMP104 Lecture 9 / Slide 2 Shortcut Assignment l C++ has a set of operators for applying an operation to a variable and then storing.
Lecture Review (If-else Statement) if-else statement has the following syntax: if ( condition ) { statement1; } else { statement2; } The condition.
For Loops Programming. COMP102 Prog Fundamentals I: for Loops/Slide 2 The for Statement condition action true false initialization update.
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
The switch Statement, DecimalFormat, and Introduction to Looping
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output.
Programming Fundamentals Lecture 4. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output.
Looping II (for statement). CSCE 1062 Outline  for statement  Nested loops  Compound assignment operators  Increment and decrement operators.
Chapter 7 Additional Control Structures. 2 2 void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response.
Computer Science Department LOOPS. Computer Science Department Loops Loops Cause a section of your program to be repeated a certain number of times. The.
Chapter 8 Iteration Dept of Computer Engineering Khon Kaen University.
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
GAME102 - INTRO WHILE LOOPS G. MacKay. Fundamental Control Structures  STRAIGHT LINE  CONDITIONAL  LOOPS.
Chapter 6.  Control Structures are statements that are used to perform repetitive tasks and to make decisions within a program. Loop repeats a sequence.
GE 211 Dr. Ahmed Telba. // compound assignment operators #include using namespace std; int main () { a =5 int a, b=3; a = b; a+=2; // equivalent to a=a+2.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Fundamental Programming Fundamental Programming More on Repetition.
Introduction to Computers and Programming Lecture 7:
REPETITION STATEMENTS - Part1  Also called LOOP STATEMENTS OR LOOP STRUCTURES 1 C++ Statements that repeat one or more actions while some condition is.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Looping Increment/Decrement Switch. Flow of Control Iteration/Switch Statements.
Chapter 4 Repetition Statements Program Development and Design Using C++, Third Edition.
Computer Programming -1-
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
1 Chapter 4 - Control Statements: Part 1 Outline 4.1 Introduction 4.4 Control Structures 4.5 if Selection Structure 4.6 if/else Selection Structure 4.7.
Chapter 4 Repetition Statements (loops)
REPETITION CONTROL STRUCTURE
while Repetition Structure
The switch Statement, and Introduction to Looping
CS161 Introduction to Computer Science
Chapter 5: Loops and Files.
Chapter 2.2 Control Structures (Iteration)
Repetition Structures (Loops)
Programming Fundamentals
Outline Altering flow of control Boolean expressions
Conditional Construct
Loops (iterations, repetitions)
3 Control Statements:.
Repetition Control Structure
Chapter 2.2 Control Structures (Iteration)
Summary Two basic concepts: variables and assignments Basic types:
Let’s all Repeat Together
Alternate Version of STARTING OUT WITH C++ 4th Edition
Repetition Statements (Loops) - 2
Programming Fundamental
REPETITION Why Repetition?
Presentation transcript:

Unary Not operator !  !true = false  !false = true

Example if ((interMarks > 45) && (testMarks >= passMarks)) { cout << “ Welcome to Lahore University”; }

Nested if If (age > 18) { If(height > 5) { : } Make a flowchart of this nested if structure…

Programming Fundamentals Lecture 6

In the last lecture Conditional Construct if if-else

Loop - Repetition structure In our day to day life, most of the things are repeated. Days and nights repeat themselves 30 times a month. Four seasons replace each other every year. We can see similar phenomenon in the practical life. For example, in the payroll system, some procedures are same for all the employees. These are repeatedly applied while dealing with the employees. So repetition is very useful structure in the programming.

Example int sum ; sum = ……..+10 ; cout << sum ;

Find the Sum of the first 100 Integer starting from 1 ?

While While means, 'do it until the condition is true'.

while ( Logical Expression ) { statements;: }

Example int sum ; sum = 0 ;

Example int sum = 0; ( Optional )

Example int sum, number ; sum = 0 ; number = 1 ; while ( number <= 1000 ) { sum = sum + number ; number = number + 1 ; } cout << “ The sum of the first 1000 integer starting from 1 is ” << sum ;

while (number <= UpperLimit)

Example int sum, number, UpperLimit ; sum = 0 ; number = 1 ; cout << “ Please enter the upper limit for which you want the sum ” ; cin >> UpperLimi t; while (number <= UpperLimit) { sum = sum + number ; number = number +1 ; } cout << “ The sum of the first ” << UpperLimit << “ integer is ” << sum ;

if ( number % 2 == 0 ) { sum = sum + number ; number = number + 1 ; }

Example sum = 0; number = 1; cout << “ Please enter the upper limit for which you want the sum ”; cin >> UpperLimit; while (number <= UpperLimit) { if (number % 2 == 0) { sum = sum + number; } number = number + 1; } cout << “ The sum of all even integer between 1 and ” << UpperLimit << “ is” << sum;

Infinite Loop: Consider the condition in the whilestructure that is (number <= upperLimit) and in the whileblock the value of numberis changing (number = number + 1) to ensure that the condition is tested again next time. If it is true, the whileblock is executed and so on. So in the whileblock statements, the variable used in condition must change its value so that we have some definite number of repetitions. What will happen if we do not write the statement number = number + 1;in our program? The value of number will not change, so the condition in the whileloop will be true always and the loop will be executed forever. Such loops in which the condition is always true are known as infinite loops as there are infinite repetitions in it.

Flow Chart for While Construct

#include void main() { int a,b; cout<<" Input the first printing value :" ; cin>>a; cout<<endl; cout<<"Input the last printing value :" ; cin>>b; cout<<endl; while(a<=b) { cout<<" The Print out value is :"<<a; cout<<endl; a++; }

Innovations Write the same program but now with fix values

#include void main() { int a; a=1; while(a<=10) { cout<<a<<endl; a++; } cout<<endl; }

Innovations Write the same program but now take values from user

Factorial Definition n! = n*(n-1)*(n-2)*(n-3)…………*3*2*1

Property of While Statement In the above example, if the user enters 0, as the value for upper limit. In the while condition we test (number <= upperLimit) i.e. number is less than or equal to upperLimit ( 0 ), this test return false. The control of the program will go to the next statement after the while block. The statements in while structure will not be executed even for a single time. So the property of while loop is that it may execute zero or more time.