Nested Loop.

Slides:



Advertisements
Similar presentations
Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.
Advertisements

Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
X=0 x
Faculty of Sciences and Social Sciences HOPE Java: Loops within loops Stewart Blakeway FML 213
1 Engineering Problem Solving With C++ An Object Based Approach Chapter 3 Control Structures.
1 Lecture 11:Control Structures II (Repetition) (cont.) Introduction to Computer Science Spring 2006.
Do/while Structure (L15) * do/while structure * break Statement * continue Statement * Loop Programming Techniques - Interactive input within a loop -
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
1 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
1 Lecture 14 Chapter 6 Looping Dale/Weems/Headington.
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
For Loops Programming. COMP102 Prog Fundamentals I: for Loops/Slide 2 The for Statement condition action true false initialization update.
Thursday, December 21, 2006 The Briggs/Chase Law of Program Development: To determine how long it will take to write and debug a program, take your best.
EXAMPLE 1 Multiplying Decimals decimal places + 2 decimal places 4 decimal places.
CHAPTER 5 CONTROL STRUCTURES II (Repetition). In this chapter, you will:  Learn about repetition (looping) control structures  Explore how to construct.
CONTROL FLOW IN C++ Satish Mishra PGT CS KV Trimulgherry.
1 What is a loop? A loop is a repetition control structure that causes a single statement or block to be executed repeatedly Loops.
Review for Quarter 1 Test 1 I. Base Ten Place-Value System II. Exponents III. Order of Operations IV. Expanded Notation.
Additional Control Structures. Chapter 9 Topics Switch Statement for Multi-way Branching Do-While Statement for Looping For Statement for Looping Using.
1 Chapter 9 Additional Control Structures Dale/Weems.
1 Do-While Statement Is a looping control structure in which the loop condition is tested after each iteration of the loop. SYNTAX do { Statement } while.
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 7 Additional Control Structures. 2 2 void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response.
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.
Computer Science Department LOOPS. Computer Science Department Loops Loops Cause a section of your program to be repeated a certain number of times. The.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
Program Flow Control - Looping Addis Ababa Institute of Technology Yared Semu April 2012.
Looping Construct or Statements. Introduction of looping constructs In looping,a sequence of statements are executed until some condition for termination.
Loops  Did you get the point behind a loop?  Why is there a need for loops? Code JunkiesLoops 1.
Control Structures RepetitionorIterationorLooping Part I.
Repetition Statements (Loops) The do while Loop The last iteration structure in C++ is the do while loop. A do while loop repeats a statement or.
1 do-while Statement 2 Do-While Statement Is a looping control structure in which the loop condition is tested after each iteration of the loop. SYNTAX.
A loop is a repetition control structure. body - statements to be repeated control statement - decides whether another repetition needs to be made leading.
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
Statements
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
REPETITION STATEMENTS - Part1  Also called LOOP STATEMENTS OR LOOP STRUCTURES 1 C++ Statements that repeat one or more actions while some condition is.
1 Programming in C++ Dale/Weems/Headington Chapter 9 Additional Control Structures (Switch, Do..While, For statements)
We have to discuss following:-  Statements  Statement flow control  Selection statement  Iteration statement.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Title Category #1 Category #2 Category #3Category #
CONTENTS Loop Statements Parts of a loop Types of Loops Nested Loops
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
Computer Programming -1-
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Infinite for Loop If you omit the test condition, the value is assumed to be TRUE so the loop will continue indefinitely unless you provide some other.
Review for Quarter 1 Test 1 I. Base Ten Place-Value II. Exponents III. Expanded Notation IV.Estimating Whole Numbers V. Order of Operations.
REPETITION CONTROL STRUCTURE
CiS 260: App Dev I Chapter 4: Control Structures II.
Programming Fundamentals
Chapter 5 Repetition.
For Loops October 12, 2017.
Loops October 10, 2017.
Iteration with While You can say that again.
Chapter 9 Control Structures.
Loops A loop is a repetition control structure.
Counting Loops.
Control structures to direct program flow
Chapter 2.2 Control Structures (Iteration)
The for Loop Syntax: Same as: for (expression1;condition; expression2)
Alternate Version of STARTING OUT WITH C++ 4th Edition
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
CS149D Elements of Computer Science
General Condition Loop
Iteration (Loop) part II
Programming Fundamental
Programming Fundamental
Presentation transcript:

Nested Loop

for (value1=0;value1<5;value1++) for (value2=0;value2<4;value2++) Cout value1”” value2 TRUE T 0 0 1 0 1 2 0 2 3 0 3 4 FALSE XXXXXXXX XX TRURE 2 0

for (int i=1;i<=3;i++) Cin>>marks Sum=sum+marks Average=sum/3 Do you want to repeat while (ans=='Y' || ans=='y'); 1 T 10 10=0+10 2 4 14=10+4 3 8 22=14+8 FALSE 7=22/3 Y TRUE

while(num!=sentinel) for (x=1;x<=12;x=x+1) enter a number while(num!=sentinel) x x<=12 total = x * num cout x * num = total num!=-1 7 TRUE 1 T 7=1x7 1 * 7 = 7 2 t 14=2 x 7 2 * 7 =14 12 84=12X7 12 * 7 =84 13 FALSE 5 7=1x5 1 * 5 = 5 14=2 x 5 2 * 5 =10 84=12X5 12 * 5 =60 -1 false

- Operation Initialization – set nilai pertama Evaluation – check T atau F Updating – increase atau decrease

Short Answer Question -Operation - 3 (a) page 119 Initialization – respond = ‘Y’; Evaluation – while (respond==‘Y’); Updating – cin>>respond;

Short Answer Question -Operation - 3 (b) page 120 Initialization – x=1 Evaluation – while (x<=100) Updating – x++

Short Answer Question - Operation - 3 (c) page 120 Initialization – a=100 Evaluation – a<0 Updating – a+=10; // a=a+10;

Question 10 (a) – trace output number Number!=-999 Sum=sum+number TRUE 100 100= 0 + 100 25 125=100+25 70 195=125+70 56 241=195+56 -999 FALSE Answer = 241

cout><<i<<“ “ Question 10(b) Do (i) = 1 i=i*4 cout><<i<<“ “ While (i<=100) 1 4= i*4 4 TRUE 16= 4 * 4 16 64= 16 * 4 64 256=64*4 256 FALSE Answer : 4 16 64 256

Question 10(c) X = 15 while (x>5) If(x==9) x-- Cout x “ ” 15 T FALSE 14 13 12 11 10 9 TRUE - break Answer : 14 13 12 11 10 9

Question 10 (d) for (x=0;x<=55;x=x+10 cout <<“hello World !” x=x+10 TRUE Hello World! 10=0+10 10 T 20=10+10 20 30=20+10 30 40=30+10 40 50=40+10 50 60=50+10 60 FALSE Thank you

Question 10 (e) 6 1 A = 2 B = 55 while a<6 b=b%2 a=a+2 Cout<<a “ “ b 2 55 TRUE 1=55%2 4=2+2 4 1 1=1%2 6=4+2 6 FALSE 6 1

cout<<g<<endl; Question f & g page 121 g While (g!=-1) i++ cin>>g; cout<<g<<endl; 100 TRUE 1 250 2 342 3 125 4 210 5 280 6 -1 FALSE

Question 10 (h) for (k=10;k>5;k=k-2) cout k k=k-2 10 TRUE 8=10-2 8 6=8-2 6 4=6-2 4 FALSE

Question 10 (j) for (i=1;i<=3;i++) for (j=1;j<=4;j++) cout<<“$” cout<<\n 1 T $ 2 3 4 5 F TRUE

for (i=1;i<=3;i++) for (j=1;j<=4;j++) x x<4 y y<2 ---------------- 1 2 3 4 FALSE TRUE $

Objektif 6 : K=5 K Cin>>value K++ K<0 5 10 6 false

Objektif 8 J=30 k k=<30 cout k k=k*2 1 TRUE 2=1*2 2 4=2*2 4 T 8=4*2 16=8*2 16 32=16*2 32 FALSE