Loop Control อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 8.

Slides:



Advertisements
Similar presentations
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Advertisements

 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
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 5: Control Structures II (Repetition)
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control Loops in Java.
Statement-Level Control Structures Sections 1-4
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.
Flow of Control Loops – Chapter 3.2. Java Loop Statements: Outline the while Statement the do-while Statement the for Statement.
Arrays, Conditionals & Loops in Java. Arrays in Java Arrays in Java, are a way to store collections of items into a single unit. The array has some number.
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
Python Control Flow statements There are three control flow statements in Python - if, for and while.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 9 - JavaScript: Control Statements II Outline 9.1 Introduction 9.2 Essentials of Counter-Controlled.
Chapter 5 Control Structures: Loops 5.1 The while Loop The while loop is probably the most frequently used loop construct. The while loop is a conditional.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
Chapter 7 LOOPING OPERATIONS: ITERATION. Chapter 7 The Flow of the while Loop.
Chapter 4 Loops Write code that prints out the numbers Very often, we want to repeat a (group of) statement(s). In C++, we have 3 major ways of.
Chapter 5 Loops. Overview u Loop Statement Syntax  Loop Statement Structure: while, for, do-while u Count-Controlled Loops u Nested Loops u Loop Testing.
Controlling Execution Dong Shao, Nanjing Unviersity.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
1 Week 6 Branching. 2 What is “Flow of Control”? l Flow of Control is the execution order of instructions in a program l All programs can be written with.
L OO P S While writing a program, there may be a situation when you need to perform some action over and over again. In such situation you would need.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Repetition Structures Repetition Structures allow you to write programs that will repeat program steps multiple times. –Also called Loops –Counter controlled.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
 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.
CS 161 Introduction to Programming and Problem Solving Chapter 18 Control Flow Through C++ Program Herbert G. Mayer, PSU Status 10/8/2014 Initial content.
Application development with Java Lecture 6 Rina Zviel-Girshin.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
COMP Loop Statements Yi Hong May 21, 2015.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
JavaScript and Ajax (Control Structures) Week 4 Web site:
Catie Welsh February 9,  Friday - No Lab! ◦ Bring questions on Project 2  Lab 3 due on Friday 2.
Chapter 3. Control Structure C++ Programing. Conditional structure C++ programming language provides following types of decision making statements. Click.
LOOPS IN ‘C’ PROGRAMMING. V ERY O FTEN, Y OU W ILL W ANT TO D O S OMETHING M ORE T HAN O NCE HA.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
Chapter 9 Repetition.
Chapter 9 - JavaScript: Control Statements II
Fundamentals of PL/SQL part 2 (Basics)
CE221 – Data Structures & Algorithms Lab Introduction
Chapter 6: Loops.
Unit-1 Introduction to Java
Loops in Java.
Control Structures.
Control Statements: Part 2
Chapter 3 Loops Section 3.3 Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Warm-up Program Use the same method as your first fortune cookie project and write a program that reads in a string from the user and, at random, will.
CiS 260: App Dev I Chapter 4: Control Structures II.
Programming Fundamentals
Chapter 5 Structures.
The Linux Command Line Chapter 29
Arrays, For loop While loop Do while loop
Loop Control Structure.
JavaScript: Control Statements (II)
MSIS 655 Advanced Business Applications Programming
Alice in Action with Java
IF if (condition) { Process… }
LRobot Game.
Loops in C.
for, do-while and switch statments
LabVIEW.
PROGRAM FLOWCHART Iteration Statements.
Repetition Structures
break & continue Statements
Presentation transcript:

Loop Control อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 8

A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages:

Java programming language provides the following types of loop to handle looping requirements. Click the following links to check their detail. Loop TypeDescription while loopRepeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. for loopExecute a sequence of statements multiple times and abbreviates the code that manages the loop variable. do...while loopLike a while statement, except that it tests the condition at the end of the loop body

While Loop while A while loop statement in java programming language repeatedly executes a target statement as long as a given condition is true. Syntax : while(Boolean_expression) { //Statements }

While Loop : Flow Diagram

While Loop : Example

for loop for A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. Syntax: for(initialization; Boolean_expression; update) { … }

for loop : Flow Diagram

for Loop : Example

do while loop do...while A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time. Syntax: do { //statements }while(Boolean_expression);

do while loop : Flow Diagram

do while Loop : Example

Loop Control Statements : Control StatementDescription break statementTerminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch. continue statementCauses the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.

break statement When the break statement is encountered inside a loop, the loop is immediately terminated and program control resumes at the next statement following the loop. It can be used to terminate a case in the switch statement

break statement Syntax: break; Flow Diagram

break : Example

continue statement In a for loop, the continue keyword causes control to immediately jump to the update statement. In a while loop or do/while loop, control immediately jumps to the Boolean expression.

break statement Syntax: continue; Flow Diagram

Continue : Example

Enhanced for loop in Java: As of Java 5, the enhanced for loop was introduced. This is mainly used to traverse collection of elements including arrays. Syntax: for(declaration : expression){ //statement }

Example

Q&AQ&A The End