Day06 A. Young W. Lim Mon. Young W. Lim Day06 A Mon 1 / 16

Similar documents
Day06 A. Young W. Lim Wed. Young W. Lim Day06 A Wed 1 / 26

Day05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14

Day02 A. Young W. Lim Sat. Young W. Lim Day02 A Sat 1 / 12

Day08 A. Young W. Lim Mon. Young W. Lim Day08 A Mon 1 / 27

GAS Tutorial - 6. Expression

Day14 A. Young W. Lim Thr. Young W. Lim Day14 A Thr 1 / 14

Second Term ( ) Department of Computer Science Foundation Year Program Umm Al Qura University, Makkah

Day14 A. Young W. Lim Tue. Young W. Lim Day14 A Tue 1 / 15

GAS Tutorial - 4. Sections & Relocation

Day21 A. Young W. Lim Wed. Young W. Lim Day21 A Wed 1 / 13

HyperGeometric Distribution

Lecture 7 Tao Wang 1

INTRODUCTION TO C++ PROGRAM CONTROL. Dept. of Electronic Engineering, NCHU. Original slides are from

2. HW/SW Co-design. Young W. Lim Thr. Young W. Lim 2. HW/SW Co-design Thr 1 / 21

Stack Tutorial. Young W. Lim Sat. Young W. Lim Stack Tutorial Sat 1 / 15

C++ Programming Lecture 7 Control Structure I (Repetition) Part I

Logic Haskell Exercises

Procedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29

Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18

Chapter 4 C Program Control

Arrays. Young W. Lim Mon. Young W. Lim Arrays Mon 1 / 17

Control. Young W. Lim Mon. Young W. Lim Control Mon 1 / 16

C++ Programming: From Problem Analysis to Program Design, Third Edition

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27

Access. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19

GAS Tutorial - 7. Directives (2)

Link 7.A Static Linking

Binary Search Tree (3A) Young Won Lim 6/2/18

Arrays. Young W. Lim Wed. Young W. Lim Arrays Wed 1 / 19

A Look Back at Arithmetic Operators: the Increment and Decrement

Algorithms Bubble Sort (1B) Young Won Lim 4/5/18

(6-1) Iteration in C H&K Chapter 5. Instructor - Andrew S. O Fallon CptS 121 (February 11, 2019) Washington State University

Link 7. Dynamic Linking

Link 3. Symbols. Young W. Lim Mon. Young W. Lim Link 3. Symbols Mon 1 / 42

Stack Debugging. Young W. Lim Thr. Young W. Lim Stack Debugging Thr 1 / 12

Control Structures II. Repetition (Loops)

An Introduction to Programming with C++ Sixth Edition. Chapter 7 The Repetition Structure

Loops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

GDB Tutorial. Young W. Lim Thr. Young W. Lim GDB Tutorial Thr 1 / 24

REPETITION CONTROL STRUCTURE LOGO

Binary Search Tree (3A) Young Won Lim 6/6/18

Binary Search Tree (3A) Young Won Lim 6/4/18

GDB Tutorial. Young W. Lim Fri. Young W. Lim GDB Tutorial Fri 1 / 24

Introduction. C provides two styles of flow control:

CIS 3260 Intro to Programming in C#

Accessibility (1A) Young Won Lim 8/22/13

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

GDB Tutorial. Young W. Lim Tue. Young W. Lim GDB Tutorial Tue 1 / 32

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Introduction to C/C++ Lecture 3 - Program Flow Control

CS110D: PROGRAMMING LANGUAGE I

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. Looping. ++ is the increment operator.

All copyrights reserved - KV NAD, Aluva. Dinesh Kumar Ram PGT(CS) KV NAD Aluva

Internet & World Wide Web How to Program, 5/e by Pearson Education, Inc. All Rights Reserved.

*Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN

Binary Search Tree (2A) Young Won Lim 5/17/18

Pointers (1A) Young Won Lim 3/5/18

204111: Computer and Programming

Chapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition

Sudeshna Sarkar Dept. of Computer Science & Engineering. Indian Institute of Technology Kharagpur

Eulerian Cycle (2A) Young Won Lim 4/26/18

Looping. Arizona State University 1

Chapter 4 C Program Control

Programming for Engineers Iteration

Control Structures (Deitel chapter 4,5)

Fundamentals of Programming Session 9

Chapter 5: Loops and Files

Introduction to the Java Basics: Control Flow Statements

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators

Fundamentals of Programming (Python) Control Structures. Sina Sajadmanesh Sharif University of Technology Fall 2017

Univariate Data - 2. Numeric Summaries

while Loops Lecture 13 Sections Robb T. Koether Wed, Sep 26, 2018 Hampden-Sydney College

Control Statements. Musa M. Ameen Computer Engineering Dept.

Link 2. Object Files

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition

Chapter 3 Structured Program Development

Link 8.A Dynamic Linking

Link 4. Relocation. Young W. Lim Wed. Young W. Lim Link 4. Relocation Wed 1 / 22

Control Structures. Control Structures Conditional Statements COMPUTER PROGRAMMING. Electrical-Electronics Engineering Dept.


V3 1/3/2015. Programming in C. Example 1. Example Ch 05 A 1. What if we want to process three different pairs of integers?

Week 2. Relational Operators. Block or compound statement. if/else. Branching & Looping. Gaddis: Chapters 4 & 5. CS 5301 Spring 2018.

C Program Control. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Univariate Data - 2. Numeric Summaries

Link 4. Relocation. Young W. Lim Thr. Young W. Lim Link 4. Relocation Thr 1 / 26

Repetition, Looping CS101

Java. Programming: Chapter Objectives. Why Is Repetition Needed? Chapter 5: Control Structures II. Program Design Including Data Structures

A Sudoku Solver (1A) Richard Bird Implementation. Young Won Lim 11/15/16

Programming Basics and Practice GEDB029 Decision Making, Branching and Looping. Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029

Example. CS 201 Selection Structures (2) and Repetition. Nested if Statements with More Than One Variable

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

Repetition Structures

The Complexity of Algorithms (3A) Young Won Lim 4/3/18

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

CompSci 125 Lecture 11

Control Statements. Objectives. ELEC 206 Prof. Siripong Potisuk

Dept. of CSE, IIT KGP

Processors. Young W. Lim. May 9, 2016

Transcription:

Day06 A Young W. Lim 2017-09-18 Mon Young W. Lim Day06 A 2017-09-18 Mon 1 / 16

Outline 1 Based on 2 Introduction C Program Control Young W. Lim Day06 A 2017-09-18 Mon 2 / 16

Based on "C How to Program", Paul Deitel and Harvey Deitel I, the copyright holder of this work, hereby publish it under the following licenses: GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License. CC BY SA This file is licensed under the Creative Commons Attribution ShareAlike 3.0 Unported License. In short: you are free to share and make derivative works of the file under the conditions that you appropriately attribute it, and that you distribute it only under a license compatible with this one. Young W. Lim Day06 A 2017-09-18 Mon 3 / 16

Repetition Essentials loop : a group of instructions which are executed repeatedly while the loop continuation condition is true counter controlled repetition : definite repetition the number of repetition is known in advance counter variable sentinel based repetition : indefinite repetition the end of data Young W. Lim Day06 A 2017-09-18 Mon 4 / 16

Counter Controlled Repetition counter variable (loop counter) the initial value the increment / decrement the test condition Young W. Lim Day06 A 2017-09-18 Mon 5 / 16

for Repetition Statement 1 the control variable is initialized 2 the loop continuation condition is checked 3 if the condition is met, the loop body is executed 4 the control variable is incremented / decremented 5 the loop continuation condition is checked 6 repeat 3~5 until the loop continuation condition fails for (init; cond; update) statement; Young W. Lim Day06 A 2017-09-18 Mon 6 / 16

for and while Repetition Statements init : initialize the loop control variable cond : the loop continuation condition update : increments / decrements the loop control variable for (init; cond; update) statement; init; while (cond) { statement; update; } Young W. Lim Day06 A 2017-09-18 Mon 7 / 16

The optional three statements in for init expression is omitted init; for ( ; cond; update) statement; cond expression is omitted for (init; ; update) statement; for (init; 1 ; update) statement; update expression is omitted for (init; cond; _) { statement; update; } infinite loop for ( ; ; ) {... if (...) break;... } Young W. Lim Day06 A 2017-09-18 Mon 8 / 16

The comma operator in for statement for (exp1, exp2; exp3, exp4; exp5, exp6) statments the comma operator: evaluates the expressions from left to right the value of the entire expression : the value of the rightmost expression condition is checked for exp4, after exp3 is executed Young W. Lim Day06 A 2017-09-18 Mon 9 / 16

do... while Repetition Statement if the initial loop continuation condition is false do... while executes the loop body at least once for and while never execute the loop body init2; do { statement; update; } while (cond2); init; while (cond) { statement; update; } for (init; cond; update) statement; Young W. Lim Day06 A 2017-09-18 Mon 10 / 16

break and continue statements break in for, while, do... while, and switch statements immediate exits from the body continue in for, while, do... while statements skips the remaining statement after continue in the body continue the next iteration of the loop while and do... while the loop continuation condition is checked immediately for the update expression is executed and then the loop continuation condition is executed Young W. Lim Day06 A 2017-09-18 Mon 11 / 16

Logical Operators to form a complex conditions logical AND : && (true when all operands are true) logical OR : (true when any operand is true) logical NOT :! logical AND true when all operands are true false when any operand is false logical OR true when any operand is true false when all operands are false Young W. Lim Day06 A 2017-09-18 Mon 12 / 16

True and False Values the result of the following operators : 0 for false, 1 for _true relational operators (>, <, >=, <=) equality operators (==,!=) logical operators (&&,,!) accepts nonzero value as a true Young W. Lim Day06 A 2017-09-18 Mon 13 / 16

Evaluation of relational operators && is higher precedence over A && B if A is true, then B is evaluated if A is false, then B needs not be evaluated (false) A B if A is true, then B needs not be evaluated (true) if A is false, then B is evaluated Young W. Lim Day06 A 2017-09-18 Mon 14 / 16

SS Young W. Lim Day06 A 2017-09-18 Mon 15 / 16

SS Young W. Lim Day06 A 2017-09-18 Mon 16 / 16