Needed in my homework at school...Thanks a lot for those who'll help...What are the some Control Structures %26amp; their Syntax in Turbo C Programming Language?
The following commands are flow control statements in C
In loops the the follow are used
break -- Passes control to the first statement following the innermost enclosing brace.
continue -- Passes control to the end of the innermost enclosing brace, allowing the loop to skip intervening statements and re-evaluate the loop condition immediately.
do -- Executes the specified statement until the value of the specified condition becomes FALSE.
Syntax do statement while ( condition );
statement The statement to be executed. statement executes repeatedly as long as the value of condition remains TRUE.
condition Either TRUE or FALSE. When FALSE, statement stops executing.
if -- Implements a conditional statement. if works exactly as it does in C++.
Syntax 1
if ( condition ) statement;
condition Must evaulate to either TRUE or FALSE. When FALSE, statement stops executing.
statement The statement to be executed. statement executes repeatedly as long as the value of condition remains TRUE.
Syntax 2
if ( condition ) statement;
else statement2;
condition Must evaulate to either TRUE or FALSE. When TRUE, statement executes. When FALSE, statement2 executes.
statement The statement to execute. statement executes repeatedly as long as the value of condition remains TRUE.
else An optional keyword. If you use nested if statements, any else statement is associated with the closest preceding if unless you force association with br aces.
statement2 The second statement to execute. statement2 executes when the value of condition is FALSE. statement2 can be another if statement.
Description
Use if to implement a conditional statement.
You can declare variables in the condition expression. For example:
if (int val = func(arg))
is valid syntax. The variable val is in scope for the if statement and extends to an else block when it exists.
The condition statement must convert to a bool type. Otherwise, the condition is ill-formed.
When %26lt;condition%26gt; evaluates to TRUE, %26lt;statement1%26gt; executes.
If %26lt;condition%26gt; is FALSE, %26lt;statement2%26gt; executes.
The else keyword is optional, but no statements can come between an if statement and an else.
for -- Executes the specified statement as long as the condition is TRUE.
Syntax for ( [initialization] ; [condition] ; [expression] ) statement
initialization Initializes variables for the loop. initialization can be an expression or a declaration. Variables are initialized before the first iteration of the loop.
condition Must evaulate to either TRUE or FALSE. When FALSE, statement stops executing.
expression The expression to evaluate after each iteration of the loop. expression usually increments or decrements the initialization variable in some way.
statement The statement to be executed. statement executes repeatedly as long as the value of condition remains TRUE.
return -- Exits from the current function, on handler, or module, optionally returning a value.
Syntax return [ expression ];
Description
A module, by default, returns TRUE if successfully run. However, an explicit return statement can be provided to return a customized return value, or simply to terminate execution prior to the end of the script.
while -- Repeats one or more statements until condition is FALSE.
Syntax while [( condition )] [{statement_list}]
condition Either TRUE or FALSE. When FALSE, statement_list stops executing.
statement_list The list of statements to execute.
Then there is Switch which acts a bit differently
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment