A control statement is any statement that affects the flow of execution.
The simplest control statement is the if statement:
if (x!=0) x++;
When execution reaches this statement, the control expression, x!=0, is evaluated. If it evaluates false (in which case x is zero) execution moves onto the next statement. However, if it evaluates true (in which case x is non-zero), the remainder of the statement is executed, incrementing x before moving onto the next statement.
The controlled statement may also be a compound statement:
if (x!=0) { x++;
x*=2;
}
As before, x!=0 is evaluated. If false, execution passes to the statement following the closing brace. If true, the compound statement is executed, first incrementing x and then doubling x. Execution then falls through to the next statement after the closing brace.
Sometimes we may wish to execute a different statement when the control expression evaluates false. In this case we use an if-else statement:
if (x==0)
x++;
else
x*=2;
Here we evaluate x==0. If true, we increment x but if false, we double x. Only one or the other statement executes, never both. Whichever is executed, execution falls through to the next statement. Again, the controlled statement may be a compound statement.
The else clause of an if statement can also be another if statement, known as a nested if:
if (x==0)
x++;
else if (x==1)
x*=2;
else if (x==2)
x*=3;
else
x*=4;
Nested ifs are evaluated in the order they appear. However, when the control expressions contain a common sub-expression (here, x), a switch is usually a better choice:
switch (x) {
case 0: x++; break
case 1: x*=2; break;
case 2: x*=3; break;
default: x*=4;
}
Here, x is evaluated and execution passes to the corresponding case label. Execution continues from that point unless a break statement is encountered, at which point execution passes to the statement that follows the closing brace of the switch statement.
Note that a break statement is also a control statement. We can also use return (another control statement) to break out of a switch.
Loops are also control statements:
for (int x=0; x<10; ++x) printf ("%d ", x);
Here we assign 0 to x, then evaluate the control expression, x<10. This is true (zero is less than ten), so the printf() function executes. We then execute the action expression, ++x, before evaluating the control expression again. this time x is 1 and 1<10 is true, so the printf() function executes again. We continue incrementing x and evaluating x<10. So long as x<10 remains true, the printf() function is invoked. After 10 iterations, x will be 10, at which point x<10 evaluates false, so execution now passes to the next statement.
We can implement the same loop using a while statement:
int x = -1;
while (++x<10) printf ("%d ", x);
Here, the initialiser is outside the loop, thus x is now in scope when the loop ends. We can do the same with for loops, provided the control variable is in scope before we enter the loop. Note that the action (++x) is now a sub-expression of the control expression. It is a matter of taste whether this code is more readable than a for loop, however for loops are arguably better suited to counted loops.
While loops are better suited to "infinite" loops such as message queues:
Message msg;
while (true) { // execute "for ever"
idle();
msg = parse_message ();
if (msg==EXIT) break;
process_message (msg);
}
This is a stylised (simplified) message queue. Here, we execute the loop continuously. We start by entering idle mode which returns when there is a message on the queue. We then parse the message. If the msg is EXIT, we break out of the loop. Otherwise we dispatch the message and repeat from the beginning. Note that "infinite" loops are never truly infinite: you must provide some means of breaking out of the loop at some point. Here we used the EXIT message.
Another control statement is the continue statement. This only appears in loops and can be used to skip over any remaining statements in the loop without breaking out of the loop.
int x = 0;
do {
++x;
if (x==5) continue;
printf ("%d ", x);
} while (x<10);
Here we print the value of x until x is 10. However, when x is 5, we do not print x, we jump to the control expression where x<10 is re-evaluated.
Note the final example shows a do-while loop and is used whenever we wish the body of the loop to execute at least once, regardless of the control expression which is evaluated at the end of each iteration, rather than at the beginning. However, the type of loop does not matter; the continue statement always skips the remainder of the loop but does not exit the loop.
A goto statement is also a control statement. However, use goto sparingly and only when required. Code that jumps about too much is difficult to read; code that is hard to read is also hard to maintain. The same can also be said of break, continue and return statements.
Function calls are also considered control statements because they (usually) interrupt the flow of execution via the call and return mechanism. The exceptions are inline expanded functions which give you all the advantages of a function (i.e., localisation of common code) without the expense of a function call.
The control structures used in java script are if-statement, for-loop, for-in loop, while loop,do-while loop, switch-statement, with-statement. try-catch-finally statements.
The break statement exits out of the smallest containing loop or switch-case statement. The continue statement transfers control to the next iteration of the smallest containing loop statement.
I think this is Branching
A return statement is used to transfer the program control flow to the function that has called the current function under execution. If the function is main, then the program returns the control flow to the operating system. The syntax for return statement is:return return-type;A goto statement is used to transfer the control flow to a particular labelled statement, not necessarily back to the calling program. There are somerestrictionson using a goto statement. For eg: the goto statement should not skip any variable declarations. The use of goto statement is usually considered as a bad programming practice. The syntax for goto statement is:goto label_name;....label_name: statements;
multiple branching is done by using ON...GOTO statement that transfers control to any number of choices
The controlling statement controls the writing you will do
Give you a prejudicial rhetorical statement?
The corollaries types of statement is what is used to explain the steps of a proof.
The corollaries types of statement is what is used to explain the steps of a proof.
differance between control statement and looping statement?
the control group is recieving the medication
The break statement exits control of the innermost for, while or do-while loop, or switch statement.
1. Single step income statement 2 – Multi-step income statement
African ethics is at crossroads the statement true.why.explain what you think is meant by the statement and give reasons for such a phenomenon?
The control structures used in java script are if-statement, for-loop, for-in loop, while loop,do-while loop, switch-statement, with-statement. try-catch-finally statements.
If someone is giving you a statement about something you're arguing you give him a response statement .
how is a fund flow statement prepared ?give your answer with imaginary figure.