8.2 looping 1 feb 2017
TRANSCRIPT
![Page 1: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/1.jpg)
APPROACH IN PROBLEM SOLVING- Control Structure
• At the end of lesson, student should able to :- explain the purpose of looping control structure- apply looping control strcuture in problem soving
- LOOPING / REPETITION
1
![Page 2: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/2.jpg)
LOOPING CONTROL STRUCTURE
2
![Page 3: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/3.jpg)
The essentials of Looping
3
![Page 4: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/4.jpg)
The essentials of Looping
4
![Page 5: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/5.jpg)
The essentials of Looping
5
![Page 6: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/6.jpg)
The essentials of Looping
6
![Page 7: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/7.jpg)
Applying Algorithm in Looping construct
7
![Page 8: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/8.jpg)
Applying Algorithm in Looping construct
Initial value
while (condition)
statement(s) to be executed if
condition is TRUE
Updating value
False
True
8
end
Start
![Page 9: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/9.jpg)
Applying Algorithm in Looping construct
9
![Page 10: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/10.jpg)
Applying Algorithm in Looping construct
10
![Page 11: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/11.jpg)
Applying Algorithm in Looping construct
bil=1
while (bil≤4)
bil=bil+1
False
True
Print “hello world”
11
end
Start
![Page 12: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/12.jpg)
Applying Algorithm in Looping construct
Bil ConditionBil≤4
Output Updating, bil=bil+1
1 T Hello world 2
2 T Hello world 3
3 T Hello world 4
4 T Hello world 5
5 F
12
![Page 13: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/13.jpg)
Applying Algorithm in Looping construct
13
![Page 14: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/14.jpg)
Applying Algorithm in Looping construct
14
![Page 15: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/15.jpg)
Applying Algorithm in Looping construct
bil=4
while (bil≥1)
bil=bil-1
False
True
Print “hello world”
15
end
Start
![Page 16: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/16.jpg)
Applying Algorithm in Looping construct
Bil ConditionBil≥1
Output Updating, bil=bil-1
4 T Hello world 3
3 T Hello world 2
2 T Hello world 1
1 T Hello world 0
0 F
16
![Page 17: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/17.jpg)
Applying Algorithm in Looping construct
17
![Page 18: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/18.jpg)
Applying Algorithm in Looping construct
18
![Page 19: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/19.jpg)
Applying Algorithm in Looping construct
bil=1
while (bil≤5)
bil=bil+1
False
True
Input width, height
area = width x height
Print area
19
end
Start
![Page 20: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/20.jpg)
Applying Algorithm in Looping construct
Bil ConditionBil≤4
Input width, height
area=width x height
Output; area
Updating, bil=bil+1
1 T 2
2 T 3
3 T 4
4 T 5
5 T 6
6 F
20
![Page 21: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/21.jpg)
Applying algorithm in looping structure
21
![Page 22: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/22.jpg)
22
End if
![Page 23: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/23.jpg)
bil=1
while (bil≤20)
bil=bil+1
False
True
Input mark
Print “status Pass”
if (mark≥50)
Print “status Fail”
True
False
23
end
Start
![Page 24: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/24.jpg)
Applying algorithm in looping structure
24
![Page 25: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/25.jpg)
Applying Algorithm in Looping construct
25
![Page 26: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/26.jpg)
Applying Algorithm in Looping construct
bil=1
while (bil≤x)
bil=bil+1
False
True
Input radius
area = 22/7 x radius x radius
Print area
Input x
26
end
Start
![Page 27: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/27.jpg)
Sentinel-controlled loop
✓ A sentinel variable is initialized to a specific value. The while loop continues until, through some action inside the loop, the sentinel variable is set to a predefined termination value.
✓ In the following example the user is asked to type characters at the keyboard, which are then appear on the screen, then press the Enter key when done.
✓ Pressing the Enter key sets the char variable answer to the ‘N’ character (defined by the special character ‘N').
27
![Page 28: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/28.jpg)
Sentinel-controlled loop
28
![Page 29: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/29.jpg)
Applying Algorithm in Looping construct
29
![Page 30: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/30.jpg)
Applying Algorithm in Looping construct
Answer = Y
while (answer ≠ N)
False
True
Print “I Love KMPK”
30
end
Start
Input answer
![Page 31: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/31.jpg)
Accumulating in problem solving
2 1 2 1
31
![Page 32: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/32.jpg)
Accumulating in problem solving
32
![Page 33: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/33.jpg)
Accumulating in problem solving
33
![Page 34: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/34.jpg)
Accumulating in problem solving
bil=1, sum = 0
While (bil≤50)
bil=bil+1
False
True
Input number
sum=sum + number
Print sum
* sum printed when condition is FALSE. Its because, when the condition is FALSE, that means all the 50 numbers already calculated by program
34
end
Start
![Page 35: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/35.jpg)
Accumulating in problem solving
35
![Page 36: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/36.jpg)
36
![Page 37: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/37.jpg)
Accumulating in problem solving
bil=1, sum = 0
while (bil≤50)
bil=bil+1
False
True
Input number
sum=sum + number
Print sum , average
* Average printed when condition is FALSE. Its because, average can calculated when all the number were input
average=sum/50
37
end
Start
![Page 38: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/38.jpg)
Summary looping- basic loop- sentinel-controlled loop- accumulating loop
38
![Page 39: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/39.jpg)
39
bil=1
while (bil≤4)
bil=bil+1
False
TruePrint
“hello world”
end
Start
Basic loop
![Page 40: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/40.jpg)
40
end
Start
Sentinel-controlled loop
Answer = Y
while (answer ≠ N)
False
True
Print “I Love KMPK”
Input answer
![Page 41: 8.2 Looping 1 Feb 2017](https://reader036.vdocument.in/reader036/viewer/2022062522/5899c2a71a28ab45548b4f1f/html5/thumbnails/41.jpg)
41
end
Start
Accumulating loop
bil=1, sum = 0
While (bil≤50)
bil=bil+1
False
True
Input number
sum=sum + number
Print sum