Category: Control Structures

In some situations we may have to change the order of execution of statements based on certain conditions , or repeat a group of statements until certain specified conditions are met. For these situation C provides decision making statements also know as control statements. C has following control statements:

 
Category: Control Structures

C has GOTO statement but one must ensure not to use too much of goto statement in their program because its functionality is limited and it is only recommended as a last resort if structured solutions are much more complicated. First let us see what the goto statement does, its syntax and functionality. The goto is a unconditional branching statement used to transfer control of the program from one statement to another.

 
Category: Control Structures

For loop: When it is desired to do initialization, condition check and increment/decrement in a single statement of an iterative loop, it is recommended to use 'for' loop.

 
Category: Control Structures

switch statement is generally best to use when you have more than two conditional expressions based on

a single variable of numeric type. For instance, rather than the code

 
 
Category: Control Structures

No, but it is not a bad idea to put default statements in switch statements for error- or logic-checking

purposes. For instance, the following switch statement is perfectly normal:

 
Category: Control Structures

C has looping , in which a sequence of statements are executed until some conditions for termination of the loop are satisfied.

 
Category: Control Structures

Switch statement is a powerful statement used to handle many alternatives and provides good presentation for C program. But there are some limitations with switch statement which are given below:

 

Logical operators cannot be used with switch statement. For instance

case k>=20:

is not allowed

Switch case variables can have only int and char data type. So float or no data type is allowed.

For instance in the switch syntax given below:

switch(ch)
{
case 1:
statement-1;
break;
case 2:
statement-2;
break;
}

In this ch can be integer or char and cannot be float or any other data type.

 

 

 


Dinesh ThakurDinesh Thakur is a Columinist and designer with strong passion and founder of Computer Notes. if you have any ideas or any request please get @me on
linkedin FaceBook Twitter Google Plus