1 st Semester 2005 1 Module4-1 Iteration statement - while อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.

Slides:



Advertisements
Similar presentations
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Advertisements

CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Control Structures Nested ifs, switch statements.
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.
Computer Science 1620 Loops.
Do/while Structure (L15) * do/while structure * break Statement * continue Statement * Loop Programming Techniques - Interactive input within a loop -
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
Chapter 5: Control Structures II (Repetition)
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
Chapter 4 Control Structure: Loop Knowledge: Understand the various concepts of loop control structure Skill: Be able to develop a program involving loop.
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
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
1 nd Semester Module3 Selection Statement Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department.
C Program Control Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
Iteration (Loop) partI Thanachat Thanomkulabut. Consider the following program! using System; Namespace SimPleExample { class SimPleC { class SimPleC.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II UTPA – Fall
1 nd Semester Module7 Arrays Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department Kasetsart.
1 st Semester Module4-1 Iteration statement - while อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
Dale Roberts Program Control using Java - Selection Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
C++ for Engineers and Scientists, Third Edition1 Objectives In this chapter, you will learn about: Basic loop structures while loops Interactive while.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
1 st Semester Module3 Condition Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
Iterations Very Useful: Ability to repeat a block of code Example:
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Control Structures RepetitionorIterationorLooping Part I.
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
2 nd Semester Looping Technique FOR…DO Module5-1 Looping Technique FOR…DO อภิรักษ์ จันทร์สร้าง Aphirak Jansang
Iteration & Loop Statements 1 Iteration or Loop Statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
CONTROL STRUCTURE Chapter 3. CONTROL STRUCTURES ONE-WAY SELECTION Syntax: if (expression) statement Expression referred to as decision maker. Statement.
CSI 3125, Preliminaries, page 1 Control Statements.
Lecture 7: Menus and getting input. switch Multiple-selection Statement switch Useful when a variable or expression is tested for all the values it can.
Flow of Control: Loops Module 4. Objectives Design a loop Use while, do, and for in a program Use the for-each with enumerations Use assertion checks.
COMP Loop Statements Yi Hong May 21, 2015.
Mindstorm NXT-G Introduction Towson University Robotics.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 5 Control Structures II: Repetition.
1 Week 9 Loops. 2 Repetition: Loops l Structure: »Usually some initialization code »body of loop »loop termination condition l Several logical organizations.
1 st Semester Module3 Condition Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
LOOPS CHAPTER Topics  Four Types of Loops –while –do…while –for –foreach  Jump Statements in Loops –break –continue 2.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
1 st Semester Module 7 Arrays อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department.
2 nd Semester Module3 Selection Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 6.
1 nd Semester Module6 Review Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department Kasetsart.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Introduction to Computer Programming
Chapter 4 – C Program Control
Unit-1 Introduction to Java
JavaScript: Control Statements I
ITM 352 Flow-Control: Loops
Programming Fundamentals Lecture #6 Program Control
JavaScript: Control Statements (II)
- Additional C Statements
.Net Programming with C#
Structured Program Development in C
Chapter 4 - Program Control
Module5 Looping Techniques: Part 2
Module5 Looping Techniques: Part 2
Module8 Multi-dimensional Array
CHAPTER 21 LOOPS 1.
Chapter 4 - Program Control
Presentation transcript:

1 st Semester Module4-1 Iteration statement - while อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department Kasetsart University, Bangkok THAILAND

1 st Semester /39 Outline  Review condition statement  Loop statements while statement do…while statement for statement  break statement

1 st Semester /39 Simple C# Structure  Namespace Class  Main()Namespace Class Main() Variable & Constant Location statements WriteLine, ReadLine, if, switch, Loop Review condition statement

1 st Semester /39 Condition Statements condition if (condition) statement; condition if (condition) statement1; else statement2; ( ) switch ( ) { case : ; break; default: ; break; } Review condition statement

1 st Semester /39 Outline  Review condition statement  Loop statements while statement do…while statement for statement  break statement

1 st Semester /39 Loop or Iteration in C# for while do…while foreach Iteration Loop statements

1 st Semester /39 Simple C# Program Start statement1 End statement1 Loop statements

1 st Semester /39 Simple C# Program with Loop Start x=5; statement1 x=x-1; End x>0 true false Loop statements

1 st Semester /39 Outline  Review condition statement  Loop statements while statement do…while statement for statement  break statement

1 st Semester /39 while statement condition statement true false while (condition) statement; while statement

1 st Semester /39 Iteration Template  Counter Controlled  Sentinel Controlled while statement

1 st Semester /39 Example3: Count Controlled  Display 1 – 7 on screen initial counter statement; dec||inc counter condition true false See demo program!!!! prog4-loop.cs while statement: counter controlled

1 st Semester /39 Iteration Template  Counter Controlled  Sentinel Controlled while statement

1 st Semester /39 Example4: Sentinel Controlled  Find summation from user input  Exit program when user input negative number See demo program!!!! prog5-loop.cs while statement: sentinel controlled

1 st Semester /39 Example 5: Display n stars See demo program!!!! prog6-loop.cs while statement: example

1 st Semester /39 Example 6: Display stars See demo!!!! prog7-loop.cs while statement: example

1 st Semester /39 Summary  Loop statements while statement do…while statement for statement  break statement