Every program follows a control path. C program control constructs are conditionals and loops. Almost every program needs to go through some sort of decision making. Decision making processes are simulated in C using conditionals. We can state a conditional as a statement that instructs the compiler to execute a function or statement if a certain condition is proved true. Decision making is done on the basis of some logic. Logic is treated as arithmetic by C compiler. The value 0 stands for true and rest any other value stands for a false value. The most common conditionals are if-else statements, switch case statements and loops.
If-else statements are used for conditional branching. It starts with if followed by an expression in its parentheses. The enclosed expression is evaluated and if the condition proves out to be true the succeeding statement is executed. If the condition is false the succeeding statement is skipped. Break and continue statements are used in if else and switch case constructs. Break will cause the execution to jump out of the loop and execute the following immediate statements whereas continue statement causes the loop to execute again and again until the condition is proved false.
Switch case begins with keyword switch followed by a variable to be switched enclosed in a parentheses. The word case is used to begin each case followed by a variable for that case, then a colon and then by the statements to be executed. Statements will be executed until a break is found. Any of the above constructs can be nested. Now coming to the go to statement, with this goto statement you can jump in between anywhere in a program except you are not allowed to jump in a loop. Goto statements are mostly risky but if there’s a place in the program where a goto statement fits , feel free to use it. However you should not be used.
Let’s define the loops now. C has 3 types of loops namely the while loop, for loop and the do while loop. The “while loop” continues to execute till the condition proves to be false. It’s an entry controlled loop which means that the loop will execute only when the condition is met. In this loop the keyword while is followed by some expression in parentheses, followed by a compound statement enclosed in braces. After reaching at the end of the loop, the control goes back to the top and the condition is revaluated.
Do while loop is an exit controlled loop. The test condition is evaluated at the end only. So even if the condition is false the loop is executed once compared to the while loop which doesn’t allows execution even once if the condition is false. You can call the do while loop as a pos check loop. This is the main difference between the while loop and the do while loop. These loops can also be nested. Nesting is unlimited. The “for loop” is the easiest loop. All its loop controlled elements are gathered at one place while in other loops they are scattered everywhere in the program. In a for loop firstly the initialization expression is executed. Then, the test expression is evaluated. If it’s true, the body of the loop is executed. After the execution the update expression is implemented, the test expression is again evaluated. If it’s true the whole sequence is repeated. You should use a for loop hen you have to repeat a block of statements specific number of times. These are the tools that programs need to perform repetitive tasks and make decisions.
Thursday, September 8, 2011
How is program controlled in C?
Posted by
Sunflower
at
9/08/2011 06:42:00 PM
0
comments
Labels: Branching, C, C Language, Compiler, Conditions, Constructs, Control, Logical, Loops, Paths, program, Program control, Statements
|
| Subscribe by Email |
|
Wednesday, July 28, 2010
High-level Best Practice Three(3) in Software Configuration Management
There are six general areas of SCM deployment, and some best practices within each of those areas. The first and second areas and there practices are already discussed.
Branching
In Software Configuration Management (SCM) systems, branching allows development to proceed simultaneously along more than one path while maintaining the relationships between the different paths. A branching strategy consists of the guidelines within an environment for the creation and application of codeline policies. There are different tools that support branching Creating a branching strategy consists of :
- identifying the categories of development that can be easily characterized,
- defining the differences and similarities between them,
- defining how they relate to each other, and
- expressing all of this information as codeline policies and branches.
High Level Practices associated with branching workspace are :
- Branch only when necessary.
- Don’t copy when you mean to branch.
- Branch on incompatible policy.
- To minimize the number of changes that need to be propagated from one branch to another, put off creating a branch as long as possible.
- Branch instead of freeze.
Posted by
Sunflower
at
7/28/2010 04:19:00 PM
0
comments
Labels: Branches, Branching, Deployment, Development, Practices, Process, SCM, Software, Software configuration management, Strategy
|
| Subscribe by Email |
|