Conditional statement: if, if else, if then, if then else, if then end if, if then else end if

By conditions we can control our program. thanks conditional statement we can control program running in two directions. if the condition is satisfied to continue running the program in a first direction, if not as the second direction. under the directions of the programme I think either statement or block of statements.

if, if else

Description

if (condition) statement1
if (condition) statement1 else statement2
Used keywords: if else

Input

Compatible programing languages:
C | Visual C++ .NET | C++ | C# | Java | JavaScript | PHP

Examples

Example

Conditional statement the possible of use:
if (i > 10)
{
i =10;            i = i - 1;   i++;
}
if (i < 10) i = 10; else i=1;

Example

Other pieces of example codes:
until (i == 0)
   if (i==10)
     break;
   else 
   {
     i--;
   }
if (i==5)
    break;
if ( y > 32 )  
   c=true;
if ( x == 5 )
   --y;
if (y<5)
   y = y/ 3.14;    // y = 1.234
if (i - 10 >0) i = i-5;

if then, if then else

Description

if condition then statement1;
if condition then statement1 else statement2;
Used keywords: if else then

Input

Compatible programing languages:
Pascal | Object Pascal | Free Pascal

Examples

Object Pascal

Conditional statement the possible of use:
if i > 10 then
begin
i :=10;            i := i - 1;   inc(i);
end;
if i < 10 then i := 10 else i:=1;

Object Pascal

Other pieces of example codes:
while i>0 do
   if i=10 then
     break
   else 
   begin
     dec(i)
   end;
if  x >= 12 then
   while  y >= 0 do  
      dec(y);
if  x = 5 then
   dec(y);
if y<5 then
   y := y/ 3.14;    // y = 1.234
if x>$abc then
  y := x / $a;    // y = 466
if  y < 100 then  
   inc(x);

if then end if, if then else end if

Description

if condition then
statements1
end if
if condition then
statements1
else
statements2
end if
Used keywords: if else then end

Input

Compatible programing languages:
Basic | FreeBASIC | Visual Basic .NET

Examples

Basic

Conditional statement the possible of use:
if i > 10 then
i =10
            i = i - 1
   i=i+1
end if
if i < 10 then
 i = 10
 else
 i=1
end if

Basic

Other pieces of example codes:
do while i<20
 i= i+2
 if i=16 then
    continue while
 end if
 x=x+1 
loop
do until i = 0
   if i=10 then
     exit do
   else
     i=i-1
   end if
loop
do
  i=i+1
  if i=5 then
    exit do
end if
loop while i <10
if x>&Habc then
  y = x / &Ha    ' y = 466
end if
if x > 0 then ' x == true
   x=5
end if
if  x = 5 then
   y=y-1
end if
Languages: en hu cz sk