There are 3 types of "if structure".
1.simple if
2.if...else structure
3.if...else if ... else structure
1.simple if
2.if...else structure
3.if...else if ... else structure
1.Simple if structure
Checks if a condition is true and executes the code specified. if the condition is false continues the execution of the main program.
program if1;
var
a:integer;
begin
writeln('Give a :');
readln(a);
if(a>0) then
writeln(a,' > ',0);
end.
2.if...else structure
Checks if a condition is valid. if the condition is true then executes the code specified. otherwise executes the else part of code.
program if1;
var
a:integer;
begin
writeln('Give a :');
readln(a);
if(a>0) then
writeln(a,' > ',0)
else
writeln(a,'<=',0);
end.
3.if...else if ... else structure
Checks multiple conditions. Executes the specified code. if none of the conditions is met , then executes the else part of the if structure.
program if2;
program if2;
var
a:integer;
begin
writeln('Give a :');
readln(a);
if(a>0) then
writeln(a,' > ',0)
else if (a=0) then
writeln(a,' = ',0)
else
writeln(a,' < ',0);
end.
No comments:
Post a Comment