Structured Program Development in C

Slides:



Advertisements
Similar presentations
CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
Advertisements

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 4 – C Program Control Outline 4.1Introduction.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
 2007 Pearson Education, Inc. All rights reserved C Program Control.
Control Structures Control structures control the flow of program execution. 3 types of control structures: sequence, selection.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved The switch Multiple-Selection Statement switch.
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
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
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
Fundamentals of C and C++ Programming Control Structures and Functions.
Control Structures Session 03 Mata kuliah: M0874 – Programming II Tahun: 2010.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
Lecture 10: Reviews. Control Structures All C programs written in term of 3 control structures Sequence structures Programs executed sequentially by default.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Lecture 4 C Program Control Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
1 4.8The do/while Repetition Structure The do/while repetition structure –Similar to the while structure –Condition for repetition tested after the body.
Control Statements Spring Semester 2013Programming and Data Structure1.
Chapter 3 Control Flow Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
Chapter 4 C Program Control. Objectives In this chapter, you will learn: –To be able to use the for and do … while repetition statements. –To understand.
Programming in Java Unit 4. Learning outcome:  LO2: Be able to design Java solutions  LO3: Be able to implement Java solutions Assessment criteria:
University of Palestine software engineering department Introduction to data structures Control Statements: Part 1 instructor: Tasneem Darwish.
Copyright © Nancy Acemian 2004 For Loops-Break-Continue COMP For loop is a counter controlled loop. For loop is a pretest loop. Used when number.
Chapter 05 (Part III) Control Statements: Part II.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (for) Outline 4.1Introduction 4.2The.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Control Statements in C 1.Decision making statements 2.Looping statements 3.Branching statements
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 9 & 10 Repetition Statements.
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
COMP Loop Statements Yi Hong May 21, 2015.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 5 Control Structures II: Repetition.
CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad.
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad.
Chapter 4 – C Program Control
Chapter 4 C Program Control Part I
Chapter 4 C Program Control Part II
Lecture 7: Repeating a Known Number of Times
Control Statements: Part 2
JavaScript: Control Statements I
CHAPTER 5A Loop Structure
Chapter 4 - Program Control
CiS 260: App Dev I Chapter 4: Control Structures II.
Ch 7: JavaScript Control Statements I.
Chapter 2.2 Control Structures (Iteration)
Repetition Structures (Loops)
JavaScript: Control Statements.
JavaScript: Control Statements I
Control Structures Lecture 7.
Programming Fundamentals Lecture #6 Program Control
MSIS 655 Advanced Business Applications Programming
Chapter 8 JavaScript: Control Statements, Part 2
Chapter 4 - Program Control
Structured Program Development in C
2.6 The if/else Selection Structure
JavaScript: Control Statements II
Chapter 4 - Program Control
Lec 6 Loop Statements Introduction to Computer Programming
Chapter 8 JavaScript: Control Statements, Part 2
Presentation transcript:

Structured Program Development in C Dr. Nouf Aljaffan Nouf Aljaffan (C) 2018

Iteration & Looping Nouf Aljaffan (C) 2018

Means of iteration: Counter-Controlled Iteration Sentinel-controlled iteration definite iteration It requires The name of a control variable (or loop counter). The initial value of the control variable. The increment (or decrement) by which the control variable is modified each time through the loop. The condition that tests for the final value of the control variable (i.e., whether looping should continue). indefinite iteration The precise number of iterations isn’t known in advance, and The loop includes statements that obtain data each time the loop is performed. Nouf Aljaffan (C) 2018

Iteration & Looping Nouf Aljaffan (C) 2018

While Iteration Statements Initialization While( condition){ statements } Nouf Aljaffan (C) 2018

While Iteration Statements Nouf Aljaffan (C) 2018

for Iteration Statement Nouf Aljaffan (C) 2018

for Iteration Statement Nouf Aljaffan (C) 2018

do…while Iteration Statement Nouf Aljaffan (C) 2018

break and continue Statements break and continue are used to alter the flow of control. Nouf Aljaffan (C) 2018

break Statement break can be used in a while, for, do…while or switch statement causes an immediate exit from that statement. Program execution continues with the next statement after that while, for, do…while or switch. Nouf Aljaffan (C) 2018

continue Statement continue can be used in a while, for or do…while Cause skipping the remaining statements in that control statement’s body and performs the next iteration of the loop. Nouf Aljaffan (C) 2018

Confusing Equality (==) and Assignment (=) Operators Nouf Aljaffan (C) 2018

Logical Operator Logical AND (&&) Operator Logical OR (||) Operator Logical Negation (!) Operator Nouf Aljaffan (C) 2018

Exercises Sum the odd integers between 1 and 99 using a for statement. Use the unsigned integer variables sum and count. Print the integers from 1 to 20 using a while loop and the counter variable x. Print only five integers per line. [Hint: Use the calculation x % 5. When the value of this is 0, print a newline character, otherwise print a tab character.] Nouf Aljaffan (C) 2018

Conclusion Variables Data Types Expression represent a single data item such as a number or character Statement caused the computer to carry out some action Branching If statement If..Else statement Nested if statement Switch statement Looping For statement While statement Do while statement Nouf Aljaffan (C) 2018

Questions? Nouf Aljaffan (C) 2018