Keywords: if, else, elsif, then, end, case, when, others, loop, while, for, in, reverse, goto, return
//if
#include <stdio.h>
int main()
{
int a=-10;
if(a<0)
{
printf("a is negative number\n");
}
printf("hello\n");
return 0;
}
with Ada.Text_IO;
use Ada.Text_IO;
procedure Hello is
a : Integer;
begin
a := -10;
if a<0 then
Put_Line("a is negative number");
end if;
Put_Line("Hello");
end Hello;
//if-else
#include <stdio.h>
int main()
{
int a,b;
a=30;
b=20;
if(a>b)
{
printf("a is bigger\n");
}
else
{
printf("b is bigger\n");
}
return 0;
}
with Ada.Text_IO;
use Ada.Text_IO;
procedure Hello is
a,b : Integer;
begin
a := 30;
b := 20;
if a>b then
Put_Line("a is bigger");
else
Put_Line("b is bigger");
end if;
end Hello;
//else if ladder
#include <stdio.h>
int main()
{
int a,b,c;
a=30;
b=20;
c=40;
if(a>b && a>c)
{
printf("a is bigger\n");
}
else if(b>a && b>c)
{
printf("b is bigger\n");
}
else
{
printf("c is bigger\n");
}
return 0;
}
with Ada.Text_IO;
use Ada.Text_IO;
procedure Hello is
a,b,c : Integer;
begin
a := 30;
b := 20;
c := 40;
if a>b and a>c then
Put_Line("a is bigger");
elsif b>a and b>c then
Put_Line("b is bigger");
else
Put_Line("c is bigger");
end if;
end Hello;
//nesting of if
#include <stdio.h>
int main()
{
int a,b,c;
a=30;
b=20;
c=40;
if(a>b)
{
if(a>c)
{
printf("a is bigger\n");
}
}
if(b>a)
{
if(b>c)
{
printf("b is bigger\n");
}
}
if(c>a)
{
if(c>b)
{
printf("c is bigger\n");
}
}
return 0;
}
with Ada.Text_IO;
use Ada.Text_IO;
procedure Hello is
a,b,c : Integer;
begin
a := 30;
b := 20;
c := 40;
if a>b then
if a>c then
Put_Line("a is bigger");
end if;
end if;
if b>a then
if b>c then
Put_Line("b is bigger");
end if;
end if;
if c>a then
if c>b then
Put_Line("c is bigger");
end if;
end if;
end Hello;
//switch case statement
#include <stdio.h>
int main()
{
int rno;
rno = 3;
switch(rno)
{
case 1: printf("rollno is 1, marks 10\n");
break;
case 2: printf("rollno is 2, marks 20\n");
break;
case 3: printf("rollno is 3, marks 30\n");
break;
case 4: printf("rollno is 4, marks 40\n");
break;
case 5: printf("rollno is 5, marks 50\n");
break;
default:printf("invalid roll number\n");
}
return 0;
}
with Ada.Text_IO;
use Ada.Text_IO;
procedure Hello is
rno : Integer;
begin
rno := 30;
case rno is
when 1 => Put_Line("rollno is 1, marks 10");
when 2 => Put_Line("rollno is 2, marks 20");
when 3 => Put_Line("rollno is 3, marks 30");
when 4 => Put_Line("rollno is 4, marks 40");
when 5 => Put_Line("rollno is 5, marks 50");
when others => Put_Line("invalid roll number");
end case;
end Hello;
//loops
#include <stdio.h>
int main(void)
{
int i;
//without loop
printf("%d\t", 1);
printf("%d\t", 2);
printf("%d\t", 3);
printf("%d\t", 4);
printf("%d\t", 5);
printf("%d\t", 6);
printf("%d\t", 7);
printf("%d\t", 8);
printf("%d\t", 9);
printf("%d\t", 10);
//while loop
i=1; //start
while(i<=10) //exit
{
printf("%d\t", i); //task
i++; //step
}
//for loop
for(i=1 ; i<=10 ; i++) //start; exit; step
{
printf("%d\t", i); //task
}
//do-while loop
i=1; //start
do
{
printf("%d\t", i); //task
i++; //step
}while(i<=10); //exit
return 0;
}
with Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Text_IO;
use Ada.Integer_Text_IO;
procedure Hello is
i : Integer;
begin
--without loop
--Put("1");put(" ");
--Put("2");put(" ");
--Put("3");put(" ");
--Put("4");put(" ");
--Put("5");put(" ");
--Put("6");put(" ");
--Put("7");put(" ");
--Put("8");put(" ");
--Put("9");put(" ");
--Put("10");put(" ");
--general loop with exit statement
--i := 1;
--loop
-- Put(i);put(" ");
-- i := i + 1;
-- exit when i>10;
--end loop;
--while loop
--i := 1;
--while i<=10 loop
-- Put(i);put(" ");
-- i := i + 1;
--end loop;
--for loop
for count in 1 .. 10 loop
Put(count);put(" ");
end loop;
end Hello;
//for loop
//in
with Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Text_IO;
use Ada.Integer_Text_IO;
procedure Hello is
begin
--for loop
for count in 1 .. 10 loop
Put(count);new_line;
end loop;
end Hello;
//in - null range
with Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Text_IO;
use Ada.Integer_Text_IO;
procedure Hello is
begin
--for loop
for count in 20 .. 10 loop
Put(count);new_line;
end loop;
end Hello;
//reverse
with Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Text_IO;
use Ada.Integer_Text_IO;
procedure Hello is
begin
--for loop
for count in reverse 1 .. 10 loop
Put(count);new_line;
end loop;
end Hello;
//reverse - null range
with Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Text_IO;
use Ada.Integer_Text_IO;
procedure Hello is
begin
--for loop
for count in reverse 10 .. 5 loop
Put(count);new_line;
end loop;
end Hello;
#include<stdio.h>
int main(void)
{
int n;
printf("Enter a number : ");
scanf("%d",&n);
if(n%2==0)
goto even;
else
goto odd;
even:
printf("Number is even\n");
goto end;
odd:
printf("Number is odd\n");
goto end;
end:
printf("\n");
return 0;
}
//ada
with Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Text_IO;
use Ada.Integer_Text_IO;
procedure Hello is
n : integer;
begin
Put("Enter a number : ");
get(n);
if (n rem 2 = 0) then
goto even;
else
goto odd;
end if;
<<even>>
Put_line("Number is even");
goto ending;
<<odd>>
Put_line("Number is odd");
goto ending;
<<ending>>
new_line;
end Hello;