PLC Session 6

In this Session we talked about Statement-Level Control Structures. As usual it was presented by our friend’s group. this session are divided into two topics

  •  Selection Statements
  • Iterative Statements

At least two additional linguistic mechanisms are necessary to make the computations in programs flexible and powerful: some means of selecting among alternative control flow paths (of statement execution) and some means of causing the repeated execution of statements or sequences of statements. Statements that provide these kinds of capabilities are called control statements .Whereas a control structure is a control statement and the collection of statements whose execution it controls. Now we move to our main topic called Selection Statements. A selection statement provides the means of choosing between two or more execution paths in a program. Selection statements divided into two general categories: two-way and n-way, or multiple selection.

Although the two-way selection statements of contemporary imperative languages are quite similar, there are some variations in their designs. The general form of a two-way selector is as shown below :

if control_expression
then clause
else clause

Control expressions are specified in parentheses if the then reserved word  is not used to introduce the then clause. We also learned that In many contemporary languages, the then and else clauses appear as either single statements or compound statements. Python uses indentation to specify compound statements. For example,

if x > y :
x = y
print “case 1”

All statements equally indented are included in the compound statement. Notice that rather than then, a colon is used to introduce the then clause in Python. Let’s move on to next topic Multiple-Selection Statements, The C multiple-selector statement, switch, which is also part of C++, Java, and JavaScript, is a relatively primitive design. Its general form is

switch (expression) {
case constant_expression1:statement1;
. . .
case constantn: statement_n;
[default: statement n+1]
}

where the control expression and the constant expressions are some discrete type. This includes integer types, as well as characters and enumeration types. The selectable statements can be statement sequences, compound statements, or blocks.To alleviate the poor readability of deeply nested two-way selectors, some languages, such as Perl and Python, have been extended specifically for this use. The extension allows some of the special words to be left out. In particular, else-if sequences are replaced with a single special word, and the closing special word on the nested if is dropped. The nested selector is then called an else-if clause. That’s the end of session, thankyou.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *