Control Statements

Today, we will learn about Control Statements in C – programming.

Untitled Diagram (14).jpg

There are two types of Conditional statements present and those are listed in above image.

  1. Iterative (for, while and do..while).
  2. Non – Iterative.

i . Conditional (goto, break, return, continue).

ii.  Unconditional (if, if…else, nested…if, switch case).

Definition :  Controlling the flow of execution of program that called..

So, we will discuss each of them and try to understand how they work.

  1. if :

Syntax :

if (condition/expression)

{

Statement1;

Satement2;

}

 

if(condition/statement);

{

statement1;

statement2;

}

In above example loop will be called as a dumy because, due to semi colon it will not enter in to the loop.

 

Example: Write a program to scan character from the user and print it’s ASCII value.

main()

{

char ch;       //variable declaration

printf(“Enter the character : “);

scanf(“%c”, &ch);

if( ch >= ‘a’ && ch <= ‘z’)

printf(“ch = %c  its ASCII value is %d \n”,ch, ch);

}

Answer : Enter the character : a

ch = a  its ASCII value is 97

 

TODO: Check the character whether it’s an upper case or lower case using if loop.

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: