SlideShare a Scribd company logo
6
Most read
10
Most read
12
Most read
Data Structures and Algorithms




    Problem Solving
    with Loops

The Loop Logic Structure
A third logic structure for designing decisions is the
loop structure. The loop logic structure is the repeating
structure.

     Types of Loop Structures

  @ WHILE / WHILE-END
  @ REPEAT / UNTIL
  @ AUTOMATIC COUNTER LOOP

Incrementing
The task of incrementing, or counting, is done by
adding a constant, such as 1 or 2, to the value of a
variable. To write the instruction to increment a
variable, you use an assignment statement. For
example:

          COUNTER = COUNTER + 1 or C = C+ 1
Problem Solving with Loops                              *Property of STI
                                                           Page 1 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops


Accumulating
Another task that a program must often perform is
accumulating, or summing a group of numbers. The
process of accumulating is similar to incrementing,
except a variable instead of a constant is added to
another variable, which holds the value of the sum or
total. The instruction for accumulating is the
following :

                        SUM = SUM + VARIABLE
                     PRODUCT = PRODUCT * NUMBER




Problem Solving with Loops                              *Property of STI
                                                           Page 2 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops

WHILE / WHILE - END
The first of the three types of loop structures is the
WHILE/WHILE-END structure. This type of loop tells
the computer that while the condition is TRUE, repeat
all instructions between the WHILE and the WHILE-
END. The form of the algorithm is the following:

                             WHILE <CONDITION(S)>
                                INSTRUCTION
                                INSTRUCTION
                                .
                                .
                                .
                             WHILE-END




Problem Solving with Loops                                *Property of STI
                                                             Page 3 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops

Flowchart Diagram of WHILE/WHILE-END




Problem Solving with Loops                    *Property of STI
                                                 Page 4 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops

Decision Equivalent to WHILE/WHILE-END




Problem Solving with Loops                     *Property of STI
                                                  Page 5 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops

Problem : Create the algorithm and the flowchart to
find the average age of all the students in a class.




Problem Solving with Loops                          *Property of STI
                                                       Page 6 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops

Repeat/Until
The second type of loop structure is the REPEAT/UNTIL
structure. This type of loop tells the computer to
repeat the set of instructions between the REPEAT and
the until, until a condition is TRUE. The format of the
REPEAT/UNTIL algorithm is the following:


                             Repeat
                              Instruction
                              Instruction
                             .
                             .
                             .
                             Until <condition(s)>




Problem Solving with Loops                                    *Property of STI
                                                                 Page 7 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops

Flowchart Diagram of REPEAT/UNTIL




Problem Solving with Loops                     *Property of STI
                                                  Page 8 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops

Decision Equivalent to REPEAT/UNTIL




Problem Solving with Loops                      *Property of STI
                                                   Page 9 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops

Problem : Create the algorithm and the flowchart to
find the average age of all the students in a class.




Problem Solving with Loops                          *Property of STI
                                                      Page 10 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops

Automatic – Counter Loop
The third type of loop structure is the automatic-
counter loop. This type of loop increments or
decrements a variable each time the loop is repeated.
The form of the algorithm for the automatic counter-
loop is the following :

                LOOP:COUNTER = BEGIN TO END STEP S
                 INSTRUCTION
                 INSTRUCTION
                 .
                 .
                 .
                LOOP-END: COUNTER




Problem Solving with Loops                            *Property of STI
                                                        Page 11 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops

Decision Equivalent to Automatic-Counter Loop




Problem Solving with Loops                       *Property of STI
                                                   Page 12 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops

Problem : Create the algorithm and the flowchart to
find the average age of all the students in a class.




Problem Solving with Loops                          *Property of STI
                                                      Page 13 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops


Nested Loops
Loops can be nested like decisions can. Each loop must
be nested inside the loop just outside it. The general
rules regarding loops, such as where the condition is
processed and how indentation and brackets are used,
hold true for nested loops as well as single loops.

The inner loops do not have to be the same types of
loop structures as the outer loops; that is, a WHILE/
WHILE-END may be nested inside a REPEAT/UNTIL loop,
or vice versa.




Problem Solving with Loops                           *Property of STI
                                                       Page 14 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops

Nested Loops




Problem Solving with Loops                  *Property of STI
                                              Page 15 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops




Problem Solving with Loops                  *Property of STI
                                              Page 16 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops

Indicators
Indicators – are logical variables that a programmer
sets within a program to change the processing path
or to control when the processing of a loop should end.

They are sometimes called flags, switches, or trip
values.


Recursion
Another type of loop structure is recursion. Recursion
occurs when a module or a function calls itself.




Problem Solving with Loops                            *Property of STI
                                                        Page 17 of 18
Data Structures and Algorithms




    Problem Solving
    with Loops




Problem Solving with Loops                  *Property of STI
                                              Page 18 of 18

More Related Content

PDF
Advance database systems (part 1)
PDF
5 problem solving with the sequential logic structure
PPTX
Data Base Management System - Basic Structure of SQL Queries
PPTX
Database architecture
DOC
K-MEDOIDS CLUSTERING USING PARTITIONING AROUND MEDOIDS FOR PERFORMING FACE R...
PPTX
17.INTRODUCTION TO SCHEMA REFINEMENT.pptx
PPTX
Coupling , Cohesion and there Types
PPTX
Feedforward neural network
Advance database systems (part 1)
5 problem solving with the sequential logic structure
Data Base Management System - Basic Structure of SQL Queries
Database architecture
K-MEDOIDS CLUSTERING USING PARTITIONING AROUND MEDOIDS FOR PERFORMING FACE R...
17.INTRODUCTION TO SCHEMA REFINEMENT.pptx
Coupling , Cohesion and there Types
Feedforward neural network

What's hot (20)

PPTX
PURPOSE OF DATABASE final.pptx
PPTX
Data Mining: Text and web mining
PPTX
Object oriented modeling and design
PPT
Database systems
PPTX
Chapter 4 Classification
PPTX
Entity Relationship Diagram
PPT
data modeling and models
PPSX
Functional dependency
PDF
Computational Thinking
PPTX
Automatic indexing
PPTX
Activation functions
PDF
Database Systems - Normalization of Relations(Chapter 4/3)
PPTX
Information retrieval s
PPT
Dbms relational model
PPT
Database concepts
PPTX
Structured Query Language (SQL)
PPT
Data models
PPTX
Activation function
PURPOSE OF DATABASE final.pptx
Data Mining: Text and web mining
Object oriented modeling and design
Database systems
Chapter 4 Classification
Entity Relationship Diagram
data modeling and models
Functional dependency
Computational Thinking
Automatic indexing
Activation functions
Database Systems - Normalization of Relations(Chapter 4/3)
Information retrieval s
Dbms relational model
Database concepts
Structured Query Language (SQL)
Data models
Activation function
Ad

Viewers also liked (20)

PDF
6 problem solving with decisions
PPTX
Algorithms and Flowcharts
PPTX
Problem Solving Flow Chart
PPTX
Algorithm and flowchart
PDF
Writing algorithms
PDF
Flowchart pseudocode-examples
PDF
Business Capability Analysis
PPT
Practices of robotics with ROBOLAB and LEGO RCX ROBOT
PPTX
Flowchart: A Problem Solving Tool
PDF
8 problem solving with the case logic structure
PDF
9 processing arrays
PDF
서울 미트업 2015 오픈 소스, 워드프레스, 그리고 커뮤니티
PDF
10 data structures
PDF
Flow chart and pseudo code
PPT
Iteration
PDF
Flowchart Power Point
PDF
Defying Logic - Business Logic Testing with Automation
PPT
2.3 Apply the different types of algorithm to solve problem
6 problem solving with decisions
Algorithms and Flowcharts
Problem Solving Flow Chart
Algorithm and flowchart
Writing algorithms
Flowchart pseudocode-examples
Business Capability Analysis
Practices of robotics with ROBOLAB and LEGO RCX ROBOT
Flowchart: A Problem Solving Tool
8 problem solving with the case logic structure
9 processing arrays
서울 미트업 2015 오픈 소스, 워드프레스, 그리고 커뮤니티
10 data structures
Flow chart and pseudo code
Iteration
Flowchart Power Point
Defying Logic - Business Logic Testing with Automation
2.3 Apply the different types of algorithm to solve problem
Ad

Similar to 7 problem solving with loops (20)

PPTX
8.2 Looping 1 Feb 2017
PDF
Repetition, Basic loop structures, Loop programming techniques
PPT
Gaddis Python 3e Chapter 04 PPT.ppt
PDF
3 programming concepts
PPT
Programming.pptVBVBBMCGHFGFDFDHGDFKJKJKKJ;J
PDF
4 introduction to programming structure
PDF
Lecture15 comparisonoftheloopcontrolstructures.ppt
PPS
02 ds and algorithm session_02
PPS
02 ds and algorithm session_02
PPTX
Object oriented programming17 control structures repetition statements
PPTX
JAN CARL BRIONES-Writing Programs Using Loops.pptx
PDF
Opject orianted programming in c++ for beg
PPTX
Daa unit 1
PDF
Loops and Files
PPT
Loop Statements [5] M
PDF
2- Algorithm Notation- Pseudocode.pptx.pdf
PDF
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
PPTX
Loop And For Loop in C++ language .pptx
PPS
01 ds and algorithm session_01
PPS
01 ds and algorithm session_01
8.2 Looping 1 Feb 2017
Repetition, Basic loop structures, Loop programming techniques
Gaddis Python 3e Chapter 04 PPT.ppt
3 programming concepts
Programming.pptVBVBBMCGHFGFDFDHGDFKJKJKKJ;J
4 introduction to programming structure
Lecture15 comparisonoftheloopcontrolstructures.ppt
02 ds and algorithm session_02
02 ds and algorithm session_02
Object oriented programming17 control structures repetition statements
JAN CARL BRIONES-Writing Programs Using Loops.pptx
Opject orianted programming in c++ for beg
Daa unit 1
Loops and Files
Loop Statements [5] M
2- Algorithm Notation- Pseudocode.pptx.pdf
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
Loop And For Loop in C++ language .pptx
01 ds and algorithm session_01
01 ds and algorithm session_01

More from Rheigh Henley Calderon (19)

PDF
2 beginning problem solving concepts for the computer
PDF
1 introduction to problem solving and programming
PPTX
9 technical support
PPTX
8 customer service
PPTX
7 laptop repair
PPTX
6 laptop basics
PPTX
5 pc maintenance
PPTX
PPTX
PPTX
2 pc assembly
PPTX
1 hardware fundamentals
PPTX
8 cyber crimes
PPTX
7 computer ethics
PPTX
6 professional ethics
PPTX
5 business ethics
PPTX
4 human relation
PPT
PPTX
3 rights and duties
PPTX
1 general ethics
2 beginning problem solving concepts for the computer
1 introduction to problem solving and programming
9 technical support
8 customer service
7 laptop repair
6 laptop basics
5 pc maintenance
2 pc assembly
1 hardware fundamentals
8 cyber crimes
7 computer ethics
6 professional ethics
5 business ethics
4 human relation
3 rights and duties
1 general ethics

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
Teaching material agriculture food technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
sap open course for s4hana steps from ECC to s4
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
KodekX | Application Modernization Development
PDF
Review of recent advances in non-invasive hemoglobin estimation
Diabetes mellitus diagnosis method based random forest with bat algorithm
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Advanced methodologies resolving dimensionality complications for autism neur...
Unlocking AI with Model Context Protocol (MCP)
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Teaching material agriculture food technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
sap open course for s4hana steps from ECC to s4
“AI and Expert System Decision Support & Business Intelligence Systems”
Reach Out and Touch Someone: Haptics and Empathic Computing
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Approach and Philosophy of On baking technology
Network Security Unit 5.pdf for BCA BBA.
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Chapter 3 Spatial Domain Image Processing.pdf
KodekX | Application Modernization Development
Review of recent advances in non-invasive hemoglobin estimation

7 problem solving with loops

  • 1. Data Structures and Algorithms Problem Solving with Loops The Loop Logic Structure A third logic structure for designing decisions is the loop structure. The loop logic structure is the repeating structure. Types of Loop Structures @ WHILE / WHILE-END @ REPEAT / UNTIL @ AUTOMATIC COUNTER LOOP Incrementing The task of incrementing, or counting, is done by adding a constant, such as 1 or 2, to the value of a variable. To write the instruction to increment a variable, you use an assignment statement. For example: COUNTER = COUNTER + 1 or C = C+ 1 Problem Solving with Loops *Property of STI Page 1 of 18
  • 2. Data Structures and Algorithms Problem Solving with Loops Accumulating Another task that a program must often perform is accumulating, or summing a group of numbers. The process of accumulating is similar to incrementing, except a variable instead of a constant is added to another variable, which holds the value of the sum or total. The instruction for accumulating is the following : SUM = SUM + VARIABLE PRODUCT = PRODUCT * NUMBER Problem Solving with Loops *Property of STI Page 2 of 18
  • 3. Data Structures and Algorithms Problem Solving with Loops WHILE / WHILE - END The first of the three types of loop structures is the WHILE/WHILE-END structure. This type of loop tells the computer that while the condition is TRUE, repeat all instructions between the WHILE and the WHILE- END. The form of the algorithm is the following: WHILE <CONDITION(S)> INSTRUCTION INSTRUCTION . . . WHILE-END Problem Solving with Loops *Property of STI Page 3 of 18
  • 4. Data Structures and Algorithms Problem Solving with Loops Flowchart Diagram of WHILE/WHILE-END Problem Solving with Loops *Property of STI Page 4 of 18
  • 5. Data Structures and Algorithms Problem Solving with Loops Decision Equivalent to WHILE/WHILE-END Problem Solving with Loops *Property of STI Page 5 of 18
  • 6. Data Structures and Algorithms Problem Solving with Loops Problem : Create the algorithm and the flowchart to find the average age of all the students in a class. Problem Solving with Loops *Property of STI Page 6 of 18
  • 7. Data Structures and Algorithms Problem Solving with Loops Repeat/Until The second type of loop structure is the REPEAT/UNTIL structure. This type of loop tells the computer to repeat the set of instructions between the REPEAT and the until, until a condition is TRUE. The format of the REPEAT/UNTIL algorithm is the following: Repeat Instruction Instruction . . . Until <condition(s)> Problem Solving with Loops *Property of STI Page 7 of 18
  • 8. Data Structures and Algorithms Problem Solving with Loops Flowchart Diagram of REPEAT/UNTIL Problem Solving with Loops *Property of STI Page 8 of 18
  • 9. Data Structures and Algorithms Problem Solving with Loops Decision Equivalent to REPEAT/UNTIL Problem Solving with Loops *Property of STI Page 9 of 18
  • 10. Data Structures and Algorithms Problem Solving with Loops Problem : Create the algorithm and the flowchart to find the average age of all the students in a class. Problem Solving with Loops *Property of STI Page 10 of 18
  • 11. Data Structures and Algorithms Problem Solving with Loops Automatic – Counter Loop The third type of loop structure is the automatic- counter loop. This type of loop increments or decrements a variable each time the loop is repeated. The form of the algorithm for the automatic counter- loop is the following : LOOP:COUNTER = BEGIN TO END STEP S INSTRUCTION INSTRUCTION . . . LOOP-END: COUNTER Problem Solving with Loops *Property of STI Page 11 of 18
  • 12. Data Structures and Algorithms Problem Solving with Loops Decision Equivalent to Automatic-Counter Loop Problem Solving with Loops *Property of STI Page 12 of 18
  • 13. Data Structures and Algorithms Problem Solving with Loops Problem : Create the algorithm and the flowchart to find the average age of all the students in a class. Problem Solving with Loops *Property of STI Page 13 of 18
  • 14. Data Structures and Algorithms Problem Solving with Loops Nested Loops Loops can be nested like decisions can. Each loop must be nested inside the loop just outside it. The general rules regarding loops, such as where the condition is processed and how indentation and brackets are used, hold true for nested loops as well as single loops. The inner loops do not have to be the same types of loop structures as the outer loops; that is, a WHILE/ WHILE-END may be nested inside a REPEAT/UNTIL loop, or vice versa. Problem Solving with Loops *Property of STI Page 14 of 18
  • 15. Data Structures and Algorithms Problem Solving with Loops Nested Loops Problem Solving with Loops *Property of STI Page 15 of 18
  • 16. Data Structures and Algorithms Problem Solving with Loops Problem Solving with Loops *Property of STI Page 16 of 18
  • 17. Data Structures and Algorithms Problem Solving with Loops Indicators Indicators – are logical variables that a programmer sets within a program to change the processing path or to control when the processing of a loop should end. They are sometimes called flags, switches, or trip values. Recursion Another type of loop structure is recursion. Recursion occurs when a module or a function calls itself. Problem Solving with Loops *Property of STI Page 17 of 18
  • 18. Data Structures and Algorithms Problem Solving with Loops Problem Solving with Loops *Property of STI Page 18 of 18