0% found this document useful (0 votes)
47 views4 pages

Soal: 1. Buatlah Contoh Program Seleksi Kondisi (If-Then-Else, Case Of) - Jawab: A. If Then Else Syntax

The document provides examples of conditional statements (if-then-else, case of) and looping statements (repeat-until, while-do, for-do) in Pascal programming language. For conditionals, it shows an if-then-else program to check if a number is between 100-1000 and a case of program to check the value between numbers 1-1000. For loops, it demonstrates a repeat-until program to check for a value 'x', a while-do program to count from 99 to a given number, and a for-do program to print a name 5 times.

Uploaded by

adi saputra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views4 pages

Soal: 1. Buatlah Contoh Program Seleksi Kondisi (If-Then-Else, Case Of) - Jawab: A. If Then Else Syntax

The document provides examples of conditional statements (if-then-else, case of) and looping statements (repeat-until, while-do, for-do) in Pascal programming language. For conditionals, it shows an if-then-else program to check if a number is between 100-1000 and a case of program to check the value between numbers 1-1000. For loops, it demonstrates a repeat-until program to check for a value 'x', a while-do program to count from 99 to a given number, and a for-do program to print a name 5 times.

Uploaded by

adi saputra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Soal :

1. Buatlah contoh program seleksi kondisi (If-then-else, Case…of).


Jawab :
a. If Then Else
 Syntax :
program angka_ratusan;
{$APPTYPE CONSOLE}
uses
Forms;
var
nilai:integer;
begin
write('Masukkan nilai :'); readln(nilai);
if (nilai>=100)and(nilai<=1000)then
writeln('Nilai Yang Anda Masukkan Termasuk Angka
Ratusan) !')
else
writeln('Nilai Yang Anda Masukkan Bukan Angka
Ratusan !');
readln;
end.

 Output :

b. Case… of
 Syntax :

program angka;
{$APPTYPE CONSOLE}
uses
forms;
var
i:char;
begin
writeln('Pilihlah nilai dibawah ini :');
writeln('A.1 B.10 C.100 D.1000 [A....D:]');readln(i);
case (i) of
'A':writeln('Angka Tersebut Satuan');
'B':writeln('Angka Tersebut puluhan');
'C':writeln('Angka Tersebut ratusan');
'D':writeln('Angka Tersebut Ribuan');
else
writeln('maaf,nilai hanya f,g,h,i saja!');
end;
readln;
end.

 Output :

2. Buatlah contoh program perulangan (Repeat…Until, While …Do, For…Do)


Jawab :
a. Repeat…Until
 Syntax :

program perulangan_repeat;
{$APPTYPE CONSOLE}
uses
forms;
var
nilai:char;
begin
repeat
write('nilai anda [x-off]:');readln(nilai);
until (nilai='x') or (nilai='x');
writeln('sudah off !');readln;
readln;
end.
 Output :

b. While…Do
 Syntax :
program batas_angka_ratusan;
{$APPTYPE CONSOLE}
uses
forms;
var
i,batas:integer;
begin
write('masukkan batas atas[diatas 99]:');readln(batas);
i:=99;
while (i<batas) do
begin
i:=i+1;
writeln('angka:',i);
end;
readln;
end.

 Output :
c. For…Do
 Syntax :
program fordo;
{$APPTYPE CONSOLE}
uses
forms;
var
i:integer;
begin
for i:=01 to 05 do
writeln(i,'. Adi Saputra ');
readln;
end.

 Output :

You might also like