for, do-while and switch statments

Slides:



Advertisements
Similar presentations
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 4 – C Program Control Outline 4.1Introduction.
Advertisements

 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
1 Loops Loops repeat (iterate) a block of statements for a number of times. A terminating condition tells a loop when to stop iterating (e.g. terminate.
 2007 Pearson Education, Inc. All rights reserved C Program Control.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
© 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 Session 03 Mata kuliah: M0874 – Programming II Tahun: 2010.
 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.
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (Switch, do-while, break) Outline 4.7The.
Programming in Java Unit 4. Learning outcome:  LO2: Be able to design Java solutions  LO3: Be able to implement Java solutions Assessment criteria:
Chapter 7 LOOPING OPERATIONS: ITERATION. Chapter 7 The Flow of the while Loop.
1. Agenda for loop Short-handed notation How to use break and continue 2.
CMSC 104, Lecture 171 More Loops Topics l Counter-Controlled (Definite) Repetition l Event-Controlled (Indefinite) Repetition l for Loops l do-while Loops.
© 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
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
Java™ How to Program, Early Objects Version, 8/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
CMSC 104, Version 9/011 More Loops Topics Counter-Controlled (Definite) Repetition Event-Controlled (Indefinite) Repetition for Loops do-while Loops Choosing.
CMSC 1041 More Loops ‘for’ loops and ‘do-while’ loops.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
Loop Control อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 8.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
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.
Introduction to Computer Programming
Chapter 9 - JavaScript: Control Statements II
Chapter 4 – C Program Control
Chapter 4 C Program Control Part I
Chapter 4 C Program Control Part II
Unit-1 Introduction to Java
Control Statements: Part 2
Control Structures II (Repetition)
Ch 7: JavaScript Control Statements I.
Chapter 2.2 Control Structures (Iteration)
JavaScript: Control Statements I
2008/10/22: Lecture 12 CMSC 104, Section 0101 John Y. Park
الحلقات التكرارية وجمل الدوران (loops)
Loop Control Structure.
Programming Fundamentals Lecture #6 Program Control
JavaScript: Control Statements (II)
MSIS 655 Advanced Business Applications Programming
- Additional C Statements
Structured Program Development in C
2008/10/22: Lecture 12 CMSC 104, Section 0101 John Y. Park
Chapter 4 - Program Control
Program Control Topics While loop For loop Switch statement
Chapter 2.2 Control Structures (Iteration)
Chapter 6 Control Statements: Part 2
© 2016 Pearson Education, Ltd. All rights reserved.
More Loops Topics Counter-Controlled (Definite) Repetition
Dale Roberts, Lecturer IUPUI
More Loops Topics Counter-Controlled (Definite) Repetition
Chapter 4 - Program Control
PROGRAM FLOWCHART Iteration Statements.
More Loops Topics Counter-Controlled (Definite) Repetition
More Loops Topics Counter-Controlled (Definite) Repetition
More Loops Topics Counter-Controlled (Definite) Repetition
Lec 6 Loop Statements Introduction to Computer Programming
More Loops Topics Counter-Controlled (Definite) Repetition
More Loops Topics Counter-Controlled (Definite) Repetition
Chapter 8 JavaScript: Control Statements, Part 2
Presentation transcript:

for, do-while and switch statments © 2016 Pearson Education, Ltd. All rights reserved.

for Iteration Statement The for iteration statement handles all the details of counter-controlled iteration. © 2016 Pearson Education, Ltd. All rights reserved.

for Iteration Statement (Cont.) General Format of a for Statement The general format of the for statement is for (initialization; condition; increment) { statement } for (j = 1; j <= 40; j ++){ printf(“%d\n”,j); © 2016 Pearson Education, Ltd. All rights reserved.

do…while Iteration Statement The do…while iteration statement is similar to the while statement. In the while statement, the loop-continuation condition is tested at the beginning of the loop before the body of the loop is performed. The do…while statement tests the loop- continuation condition after the loop body is performed. © 2016 Pearson Education, Ltd. All rights reserved.

do…while Iteration Statement (Cont.) do{ statement }while (condition); © 2016 Pearson Education, Ltd. All rights reserved.

© 2016 Pearson Education, Ltd. All rights reserved. break and continue continue Statement The continue statement, when executed in a while, for or do…while statement, skips the remaining statements in the body of that control statement and performs the next iteration of the loop. Break Statement The break statement, when executed in a while, for or do…while statement, terminates the loop. © 2016 Pearson Education, Ltd. All rights reserved.

© 2016 Pearson Education, Ltd. All rights reserved.  switch statement Transfers control to one of the several statements, depending on the value of a condition. switch(x) { case 1 : printf(“1”); break; case 2 : printf(“2”); break; case 3 : printf(“3”); break; } © 2016 Pearson Education, Ltd. All rights reserved.