iteration control structure
Download
Skip this Video
Download Presentation
Iteration Control Structure

Loading in 2 Seconds...

play fullscreen
1 / 33

Iteration Control Structure - PowerPoint PPT Presentation


  • 75 Views
  • Uploaded on

Iteration Control Structure. Fourth Quarter. Fundamental Concept. Involves loops or cycles Loops : means that a process may be repeated as long as certain condition remains true or remains false. Means “ multiple processing ”

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Iteration Control Structure' - sunila


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
fundamental concept
Fundamental Concept
  • Involves loops or cycles
    • Loops: means that a process may be repeated as long as certain condition remains true or remains false.
    • Means “multiple processing”
  • Provides means of repeating a part of instruction without rewriting the part again and again.
parts of the loop
Parts of the Loop
  • Body of the Loop : Set of statements which is repeated.
  • Loop Exit Condition: condition to be tested before each repetition.
parts of the loop 3 s
Parts of the Loop: 3 S
  • Start : the starting or the beginning point of the loop.
  • One may start with first or the last record in the file.
slide5

Step : the manner on how the records are to be processed in the given file.

Proper sequencing is needed (ascending or descending).

slide6

Stop : the ending point . It is normally represented in a form of a conditional expression, thus, a decision symbol is used in the flowchart

control variable
Control Variable
  • Is a variable that defines the starting, ending point and step of a looping statement.
  • It should be a variable that will uniquely identify all the records in the file.
  • It is a representation of a field in the record. The shorter the value, the better is the field
problem no 1
Problem No. 1
  • Draw a flowchart that will read the grades in PT, CS and QS of student. Compute the average of the student. Print the name and the computed average.
      • Input :
      • Process:
      • Output:
      • Will there be multiple processing? How many times the inputting, processing and outputting will be performed? WHY?
slide9

Problem No. 2

  • Draw a flowchart that will read the grades in PT, CS and QS of all the students in the class of II - ____. Compute the average of all the students. Print the names and the computed averages.
      • Input :
      • Process:
      • Output:
      • Will there be multiple processing? How many times the inputting, processing and outputting will be performed? WHY?
counters
Counters
  • Are used to literally count the number of times a portion of the flowchart is traced.
  • Need to be initialized / prepared prior to its use or application.
  • The operation involved is “addition”
  • The increment value is a constant
  • Example: C = C + 1

Increment Value

Current Value

New Value

accumulators
Accumulators
  • A numerical value that collects the result of a repeated mathematical operation.
  • Used to keep a running total of an item / the operation involved is “addition”.
  • Need to be initialized / prepared prior to its use or application.
  • The incremental value is a “variable” (subjected to change)
  • Example: S = S + N

Increment Value

                  • Current Value

New Value

looping statements
Looping Statements
  • Executes a group of instructions repeatedly
  • Has 3 Structures:
    • For ……. Next
    • Do …….. Loop : has three types:
              • Do While …. Loop
              • Do Until …. Loop
              • Do …… Loop while
    • While ….. Wend
for next statement
For …. Next Statement
  • Executes a section of the code a specified number of times.
  • Begins with the “for” statement and ends with the “next” statement.
  • Can only be used if the programmer knows the number of times the loop must be performed prior to its execution.
for next syntax 1 no skipping
For … Next Syntax 1(no skipping)

For <counter > = <Start> to <Stop> Step <Step>

<Statements>

Next <counter>

example
Example:

Dim UserName as string

Dim times as integer

Username = “Paul”

Lbloutput.text = “ ”

For times = 1 to 10 step 1

Lbloutput.text = lbloutput.text & chr(13) & Username

Next times

example1
Example:

Dim UserName as string

Dim times as integer

Username = “Paul”

Lbloutput.text = “ ”

For times = 1 to 10

Lbloutput.text = lbloutput.text & chr(13) & Username

Next

for next syntax 2 with skipping decrement
For … Next Syntax 2(with skipping/decrement)

For <counter > = <Start> to <Stop> Step <Step>

<Statements>

Next <counter>

example 1
Example 1

Dim counter as integer

Lbloutput.text = “”

For counter = 10 to 1 step -1

lbloutput.text = lbloutput.text & chr(13) & counter

Next

example 2
Example 2

Dim counter as integer

Lbloutput.text = “”

For counter = 9to 1 step -2

lbloutput.text = lbloutput.text & chr(13) & counter

Next

do while loop
Do while ….. Loop
  • Most common statement among the do ..loop statements
  • Test condition appears at the TOP of the loop
    • As long as the test condition is TRUE, the block of code in the body of the loop will be continuously executed
    • When the test condition becomes FALSE, the loop terminates.
  • Condition before iteration
syntax do while loop
Syntax: Do while …. Loop

Do while <condition>

<statement>

<statement>

Loop

example2
Example:

Private Sub Command1_Click( )

Dim N As Integer

N = 0

Do While N < 10

N = N + 1

Print N

Loop

End Sub

example3
Example:

Private Sub Command1_Click( )

Dim N As Integer

N = 0

Do While N < 10

N = N + 1

Print N

Loop

End Sub

Loop Statement

do loop while
Do ….. Loop While
  • The test condition appears at the bottom of the loop.
  • When the test condition stays TRUE, the loop still executes until it becomes false
  • Condition after iteration
do loop while syntax
Do … Loop While Syntax

Do

< statement >

< statement >

< statement >

Loop while < condition >

example4
Example:

Private Sub Command1_Click( )

Dim N As Integer

N = 0

Do

N = N + 1

Print N

Loop While N < 10

End Sub

do until loop
Do Until …. Loop
  • Test condition also appears at the TOP of the LOOP.
  • Executes the block of statements as long as the test condition is FALSE
do until loop syntax
Do Until … Loop Syntax

Do until < condition >

< statement >

< statement >

Loop

example5
Example:

Private Sub Command1_Click( )

Dim N As Integer

N = 0

Do Until N >= 10

N = N + 1

Print N

Loop

End Sub

do while do until
DO WHILE / DO UNTIL

Display numbers from

1 to 10

Do While N < 10

N = N + 1

Print N

Body of Loop will be executed as long as the condition is TRUE.

Display numbers from

1 to 10

Do Until N >= 10

N = N + 1

Print N

Body of Loop will be executed as long as the condition is FALSE.

activity 1 2
Activity 1 & 2
  • Make a program that will display “Patience is a Virtue” 5 times.
  • Make a program that will display this output on the form:
slide33

Filenames:

    • Activity No.1
        • 4Act12CN
    • Activity No.2
        • 4Act22CN
ad