Download presentation

Presentation is loading. Please wait.

Published byTatyana Yarrow Modified over 2 years ago

1
Looping while … do …

2
Condition Process 2 Process 1 Y Repeated Loop

3
Condition Process 1 Process 3 N

4
Condition Process 2 Process 1 Process 3 Y N while … do...

5
i<=5 i:=i+1; i=1; Y while i<=5 do i:=1; writeln(i); i:=i+1; begin end; i=1output 1i=2output 2i=3output 3i=4output 4i=5output 5i=6? writeln(i);

6
i<=5 i=1; N end.

7
i<=5 i:=i+1; i=1; Y N end. writeln(i);

8
Ex.1 Use “while…do” to write a program to accept any integer and output its square value until the user input a negative number. The output should be as follow. The value after “:” is inputted by user. Welcome! Input an integer: 9 Square of 9 is 81 Input an integer:4 Square of 4 is 16 Input an integer:7 Square of 7 is 49 Input an integer: Bye!

9
Welcome! Input an integer: 9 Square of 9 is 81 Input an integer:4 Square of 4 is 16 Input an integer:7 Square of 7 is 49 Input an integer: -1 Bye! while…do … segment Ex.1 Use “while…do” to write a program to accept any integer and output its square value until the user input a negative number. The output should be as follow. The value after “:” is inputted by user.

10
n>=0 Y write(‘Input an integer’); readln(n); writeln(‘Square of ’, n,’ is ’,sqr(n)); write(‘Input an integer’); readln(n); N writeln(‘Bye!’); inputn>=0n=9n=4n=7n=-1 Y Y Y N Ex.1

11
program ex1; var n:integer; begin writeln(‘Welcome!’); write(‘Input an integer: ’); readln(n); while n>=0 do begin writeln(‘Square of ’,n,‘ is ’,sqr(n)); write(‘Input an integer: ’); readln(n); end; writeln(‘Bye!’); end.

12
Looping repeat … until …

13
Condition Process 2 Process 1 N Repeated Loop

14
Condition Process 2 Process 1 Y Process 3

15
Condition Process 2 Process 1 N Y Process 3 repeat … until...

16
writeln(i); i:=1; i:=i+1; repeat until i>5; i>5 i:=1; N i:=i+1; i>5 writeln(i); i=2Ni=3Ni=4Ni=5Ni=6?

17
writeln(i); i:=1; i:=i+1; repeat until i>5; i>5 i:=1; Y i:=i+1; end. writeln(i); i>5 i=2Ni=3Ni=4Ni=5Ni=6Y

18
writeln(i); i:=1; i:=i+1; repeat until i>5; i>5 i:=1; N i:=i+1; Y end. writeln(i);

19
Condition Process 2 Process 1 Process 3 Y N Condition Process 2 Process 1 N Y Process 3 Compare while … do … and repeat … until... Condition Process 2

20
Ex.2 Use “repeat …until” to write a program to accept any integer and output its square value until the user inputs a negative number. The output should be as follows. The value after “:” is inputted by user. Welcome! Input an integer: 9 Square of 9 is 81 Input an integer:4 Square of 4 is 16 Input an integer:7 Square of 7 is 49 Input an integer: Bye!

21
Welcome! Input an integer: 9 Square of 9 is 81 Input an integer:4 Square of 4 is 16 Input an integer:7 Square of 7 is 49 Input an integer: -1 Bye! repeat …until … segment Ex.2 Use “repeat …until” to write a program to accept any integer and output its square value until the user inputs a negative number. The output should be as follows. The value after “:” is inputted by user.

22
n<0 Y write(‘Input an integer’); readln(n); writeln(‘Square of ’, n,’ is ’,sqr(n)); write(‘Input an integer’); readln(n); N writeln(‘Bye!’); inputn<0n=9n=4n=7n=-1 N N N Y Ex.2

23
program ex2; var n:integer; begin writeln(‘Welcome!’); write(‘Input an integer: ’); readln(n); repeat writeln(‘Square of ’,n,‘ is ’,sqr(n)); write(‘Input an integer: ’); readln(n); until (n<0); writeln(‘Bye!’); end.

Similar presentations

OK

Program Design. The design process How do you go about writing a program? –It’s like many other things in life Understand the problem to be solved Develop.

Program Design. The design process How do you go about writing a program? –It’s like many other things in life Understand the problem to be solved Develop.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Presenter media free download ppt on pollution Ppt on group development tuckman Ppt on forex exchange market Ppt on power system harmonics pdf Download ppt on fundamental rights and duties citizens Ppt on hydraulic free piston engine Ppt on life cycle of silk moth Ppt on the portrait of a lady Ppt on machine translation Ppt on two point perspective lesson