Download presentation

Presentation is loading. Please wait.

Published byYazmin Wardwell Modified over 2 years ago

1
For to do loop for i:=1 to 10 do writeln(i); While do loop i:=1; while i<=10 do begin writeln(i); i:=i+1; end; Repeat until loop i:=1; repeat writeln(i); i:=i+1; until i>10; increase the value of i by 1 E.g.9

2
For to do loop for i:=6 to 12 do writeln(i*2); While do loop i:=6; while i<=12 do begin writeln(i*2); i:=i+1; end; Repeat until loop i:=6; repeat writeln(i*2); i:=i+1; until i>12; E.g.10 increase the value of i by 1

3
for a:=1 to 10 do Begin write(a*3,’ square is ’); writeln(sqr(a*3)) End. Ex.3 For to do loop

4
a:=1; while a<=10 do begin write(a*3, ‘square is ’); writeln(sqr(a*3)); a:=a+1; end; Ex.3 While do loop

5
a:=1; repeat write(a*3, ‘square is’); writeln(sqr(a*3)); a:=a+1; until a>10; Ex.3 Repeat Until loop

6
for i:=1 to 5 do begin for j:=1 to i do write(‘*’); writeln; End. Ex.4 For to do loop

7
i:=1; while i<=5 do begin j:=1; while j<=i do begin write(‘*’); j:=j+1; end; writeln; i:=i+1; end; Ex.4 while do loop

8
i:=1; repeat j:=1; repeat write(‘*’); j:=j+1; until j >i; writeln; i:=i+1; until i>5; Ex.4 repeat until loop

9
Ex.Game Use “while..do’’ or ‘’repeat..until” to write a program which let the user guesses a number from 1 to 10 until he got the random number generated by computer. The output should be as follows. The value after “guess ->” is inputted by user. Guess the number from 1 to 10 Guess -> 1 Guess the number from 1 to 10 Guess -> 2 Guess the number from 1 to 10 Guess -> 3 Good! You got the number!

10
Guess the number from 1 to 10 Guess -> 1 Guess the number from 1 to 10 Guess -> 2 Guess the number from 1 to 10 Guess -> 3 Good! You got the number! repeated segment Ex.Game Use “while..do’’ or ‘’repeat..until” to write a program which let the user guesses a number from 1 to 10 until he got the random number generated by computer. The output should be as follows. The value after “guess ->” is inputted by user.

11
key <> guess N Write(‘Guess ->’); readln(guess); write(‘Guess the number from 1 to 10’); Y writeln(‘Good!You got the number!’); Ex.Game (while do loop) Random a number

12
Program game Var key,guess:integer; begin randomize; key:=random(10)+1; writeln(‘Guess the number from 1 to 10’); write(‘Guess ->’); readln(guess); while guess<>key do begin writeln(‘Guess the number from 1 to 10’); write(‘Guess ->’); readln(guess); end; writeln(‘Good!’ You got the number!’); end. Random function Ex.Game (while do loop)

13
key = guess Y Write(‘Guess ->’); readln(guess); writeln(‘Guess the number from 1 to 10’); N writeln(‘Good!You got the number!’); Ex.Game (repeat until loop) Random a number

14
Program game; var key,guess:integer; begin randomize; key:=random(10)+1; repeat writeln('Guess the number from 1 to 10'); write('Guess -> '); readln(guess); until key=guess; writeln('Good! You got the number!'); end. Ex.Game (repeat until loop)

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google