Control Structures Session 03 Mata kuliah: M0874 – Programming II Tahun: 2010.

Slides:



Advertisements
Similar presentations
More on Algorithms and Problem Solving
Advertisements

 Control structures  Algorithm & flowchart  If statements  While statements.
Session 5 JavaScript/JScript: Control Structures II Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 4 – C Program Control Outline 4.1Introduction.
4 Control Statements.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control.
 2007 Pearson Education, Inc. All rights reserved C Program Control.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
Structured Program Development in C
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
CIS3931 – Intro to JAVA Lecture Note Set 3 19-May-05.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 9 - JavaScript: Control Statements II Outline 9.1 Introduction 9.2 Essentials of Counter-Controlled.
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.
Jaeki Song ISQS6337 JAVA Lecture 04 Control Structure - Selection, and Repetition -
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II UTPA – Fall
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (Switch, do-while, break) Outline 4.7The.
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
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.
C Lecture Notes 1 Structured Program Development.
1 C++ How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved. 4.
C++ Programming Lecture 6 Control Structure II (Repetition) By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Chapter 04 Control Statements: Part II. OBJECTIVES In this part you will learn: if…else Double-Selection Statement. while Repetition Statement.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (for) Outline 4.1Introduction 4.2The.
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
1 Chap 4. Data Should know Declare & Initialize variables Declare constants Assignment Operators Increment and Decrement Operators Precedence of Operators.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
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
Lecture 4: C/C++ Control Structures Computer Programming Control Structures Lecture No. 4.
Structured Program Development Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 9 & 10 Repetition Statements.
Control Structures - Selections - Repetitions/iterations (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 10 - JavaScript/JScript: Control Structures II Outline 10.1Introduction 10.2Essentials of.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Essentials of Counter-Controlled Repetition Counter-controlled repetition requires: Control variable (loop counter) Initial value of the control variable.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
ECE122 Feb 10, Unary Operator An operator that takes only a single operand Plus: + Minus: – Cast: (type). E.g. (double)
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
 By the end of this section you should be able to: ◦ Differentiate between sequence, selection, and repetition structure. ◦ Differentiae between single,
Branching statements.
JavaScript: Control Statements I
TMF1414 Introduction to Programming
CiS 260: App Dev I Chapter 4: Control Structures II.
Chapter 2.2 Control Structures (Iteration)
Lecturer CS & IT Department UOS MBDIN
Control Statements Kingdom of Saudi Arabia
JavaScript: Control Statements.
JavaScript: Control Statements I
Programming Fundamentals Lecture #6 Program Control
Structured Program Development in C
Structured Program
Chapter 3 - Structured Program Development
3 Control Statements:.
Chapter 2.2 Control Structures (Iteration)
Chapter 3 - Structured Program Development
2.6 The if/else Selection Structure
EPSII 59:006 Spring 2004.
Control Statements Paritosh Srivastava.
Structural Program Development: If, If-Else
Presentation transcript:

Control Structures Session 03 Mata kuliah: M0874 – Programming II Tahun: 2010

Bina Nusantara University 3 Outline Materi Pseudocode Control Structure If Selection Structure If/else Selection Structure While Repetition Structure Assignment Operators Increment and Decrement Operators For Repetition Structure Switch Multiple-Selection Structure Do/While Repetition Structure Statements break and continue

Bina Nusantara University 4 Pseudocode An artificial an informal language that helps programmers develop algorithms. Similar to everyday english; it is convenient and user-friendly, and it is not an actual computer programming language. Not executed on computers. Helps the programmer “think out” a program before attempting to write it in a programming language.

Bina Nusantara University 5 Control Structure Three types of selection structures: If selection structure If/else selection structure Switch selection structure Four repetition structures: While Do/while For Foreach

Bina Nusantara University 6 If Selection Structure If student’s grade is greater than or equal to 60 Print “passed” Pseudocode if statement: if ( studentGrade >= 60 ) Console.WriteLine ( “Passed” );

Bina Nusantara University 7 Flow chart If Selection Structure

Bina Nusantara University 8 If/else Selection Structure If student’s grade is greater than or equal to 60 Print “Passed” else Print “Failed” Pseudocode if/else structure: if ( studentGrade >= 60 ) Console.WriteLine( “Passed” ); else Console.WriteLine( “Failed” );

Bina Nusantara University 9 Flow Chart If/else Selection Structure

Bina Nusantara University 10 Nested if/else if student’s grade is greater than or equal to 90 Print “A” else if student’s grade is greater than or equal to 80 Print “B” else if student’s grade is greater than or equal to 60 Print “C” else Print “D”

Bina Nusantara University 11 Nested if/else Pseudocode may be written as: if ( studentGrade >= 90 ) Console.WriteLine ( “A” ); else if ( studentGrade >= 80 ) Console.WriteLine ( “B” ); else if ( studentGrade >= 60 ) Console.WriteLine( “C” ); else Console.WriteLine( “D” );

Bina Nusantara University 12 Nested if/else Most C# programmers prefer to write the preceding if structure as: if ( studentGrade >= 90 ) Console.WriteLine ( “A” ); else if ( studentGrade >= 80 ) Console.WriteLine ( “B” ); else if ( studentGrade >= 60 ) Console.WriteLine( “C” ); else Console.WriteLine( “D” );

Bina Nusantara University 13 While Repetition Structure Specify that an action is to be repeated while a condition remains true. The pseudocode statement While there are more items on my shopping list Purchase next item and cross it off my list Example: int product = 2; while ( product <= 1000 ) product = 2 * product

Bina Nusantara University 14 While Repetition Structure

Bina Nusantara University 15 Assignment Operators Assume: int c = 3, d = 5, e = 4, f = 6, g = 12 Assignment operatorSample expressionExplanationAssigns +=c += 7c = c to c -=d -= 4d = d - 41 to d *=e *= 5e = e * 520 to e /=f /= 3f = f / 52 to f %=g %= 9g = g % 93 to g

Bina Nusantara University 16 Increment and Decrement Operators

Bina Nusantara University 17 Increment and Decrement Operators

Bina Nusantara University 18 Increment and Decrement Operators Output:

For Repetition Structure for keyword counter variable name final value of control variable for ( int counter = 1; counter <= 5; counter++ ) Initial value of control variable loop-continuation condition increment of control var Bina Nusantara University 19 for ( expression1; expression2; expression3 ) statement

Bina Nusantara University 20 For Repetition Structure

Bina Nusantara University 21 For Repetition Structure

Bina Nusantara University 22 Switch Multiple-Selection Structure

Bina Nusantara University 23 Do/While Repetition Structure Do/while repetition structure is similar to the while structure. In the while structure, the test of the loop- continuation condition occurs at the beginning of the loop, before the body of the loop executes. The do/while structure tests the loop-continuation condition after the loop body executes; therefore, the loop body always executes at least once.

Bina Nusantara University 24 Do/While Repetition Structure do statement OR{ while ( condition );statement } while ( condition );

25 Do/While Repetition Structure

Bina Nusantara University 26 Statements break and continue The break and continue statements alter the flow of control. The break statement, when executed in a while, for, do/while or switch structure, cause immediate exit from that structure. The continue statement, when executed in a while, for or do/while structure, skips the remaining statements in the body of that structure and proceeds with the next iteration of the loop.

Bina Nusantara University 27 Statements break and continue

Bina Nusantara University 28 Statements break and continue

Bina Nusantara University 29 References &printsec=frontcover&dq=c%23&cd=2#v=onepage& q=&f=falsehttp://books.google.co.id/books?id=8R451rZJ5o0C &printsec=frontcover&dq=c%23&cd=2#v=onepage& q=&f=false