COS 333: Chapter 8, Part 1
Summary
TLDRThis lecture delves into statement-level control structures, focusing on selection statements like if-else and switch-case. It explores the evolution of control structures post-FORTRAN, emphasizing the sufficiency of two-way selection and pre-test loops over go-to statements. The lecture discusses design issues in selection statements, including control expression types, clause specifications, and nested selector disambiguation across various programming languages. It also covers multiple-way selection statements, comparing their implementation in languages like C, C#, Java, JavaScript, and Ruby, highlighting differences in syntax and semantics.
Takeaways
- 📚 The lecture introduces chapter eight on statement level control structures, focusing on selection statements and their design issues.
- 🔍 The discussion differentiates between control within expressions, among program units, and among program statements, with the latter being the focus of the chapter.
- 🔄 Historical context is provided on the development of control statements, highlighting the shift from hardware-specific to more generalized structures post-FORTRAN.
- 🛑 The redundancy of unconditional branching statements like 'go to' is established, with algorithms able to be represented using only two-way selection and pre-test loops.
- 🔑 Control structures are defined as comprising a control statement and the statements under its control, with a design issue being whether to allow multiple entry points.
- ❓ The use of 'go to' statements for multiple entry points is generally seen as reducing readability without significantly increasing flexibility.
- 🔼 Two-way selection statements are detailed, with 'if-else' constructs being the primary example, and their design issues such as control expression form and type, clause specification, and nested selector disambiguation.
- 🌐 Programming language variations in handling two-way selection statements are highlighted, including differences in how then and else clauses are specified and nested if-else structures are disambiguated.
- 🔠 The importance of the control expression's type is noted, with some languages allowing arithmetic expressions while others require boolean types.
- 🔀 Multiple way selection statements, akin to 'switch' or 'case' statements, are introduced with five key design issues discussed, including form and type of control expression, segment specification, and handling of unrepresented values.
- 📝 The chapter concludes with a look at iterative statements, unconditional branching, and guarded commands to be covered in the subsequent lecture.
Q & A
What is the main focus of the lecture on chapter eight?
-The lecture on chapter eight focuses on statement level control structures, including an introduction to these structures and a detailed discussion on selection statements.
What are the different levels of control that can be discussed in programming languages?
-The different levels of control in programming languages include control within expressions, control flow among program units (sub-programs or methods/functions), and control flow among program statements.
Why was there a heavy reliance on jumps or go-to statements in FORTRAN I?
-FORTRAN I was designed to work with the IBM 704 hardware, which meant that the control statements were based directly on the hardware, making the control structures very specific and leading to a heavy reliance on jumps or go-to statements.
What was a significant outcome of the research and arguments in the 1960s regarding control statements?
-A significant outcome was the understanding that all flowchart-represented algorithms can be coded with only two-way selection statements and pre-test logical loops, making unconditional branching statements like jumps or go-to statements unnecessary.
What is a control structure in the context of programming?
-A control structure consists of a control statement, such as an if statement or a while statement, and the statements whose execution the control structure manages.
Why are go-to statements and multiple entry points generally considered to decrease readability in programming?
-Go-to statements and multiple entry points can make the flow of a program less clear and more difficult to follow, which can lead to decreased readability and maintainability of the code.
What are the two general categories of selection statements?
-The two general categories of selection statements are two-way selectors and multiple way selectors.
How does the use of parentheses affect the control expression in a two-way selection statement?
-Parentheses are used to clearly delimit the control expression, ensuring that the condition is clearly defined and separated from the rest of the statement.
What is the purpose of an else clause in a selection statement used as an expression, as seen in some languages like ML or F#?
-In languages where a selection statement is used as an expression and can return a value, the else clause is required to provide an alternative value when the condition is not met, ensuring that the expression always returns a value.
How does the design of switch statements in C and similar languages address the issue of control flowing through multiple segments?
-The design requires an explicit unconditional branch, such as a break, at the end of each selectable segment to prevent control from flowing inadvertently to the next segment.
What is the difference between C and C# when it comes to multiple way selection statements?
-C# differs from C by having a semantic rule that disallows implicit execution of more than one segment and by allowing both the control expression and the case constants to be strings.
How does Ruby handle multiple way selection statements with case expressions?
-Ruby's case expressions can either use a sequence of when conditions without a control expression or use a case value as a control expression with when values, and they can return a result because they are treated as expressions.
What is the advantage of using boolean multiple-way selection statements over nested two-way selection statements?
-Boolean multiple-way selection statements can improve readability by avoiding the complexity and potential confusion of nested if-then-else statements.
Outlines
📘 Introduction to Statement Level Control Structures
This paragraph introduces the topic of statement level control structures, which is the focus of chapter eight. It outlines the lecture's agenda, including an introduction to these structures and an in-depth discussion on selection statements. The historical context of FORTRAN and the evolution of control statements is provided, highlighting the shift away from low-level, hardware-specific control structures towards more abstract, high-level constructs. The paragraph also emphasizes the debate in the 1960s about the best practices for control statements, leading to the conclusion that two-way selection statements and pre-test loops can suffice for all flowchart algorithms, rendering unconditional branches unnecessary.
🔍 Design Issues of Two-Way Selection Statements
The second paragraph delves into the design considerations for two-way selection statements, such as 'if-else' constructs. It discusses the form and type of the control expression, the specification of 'then' and 'else' clauses, and the disambiguation of nested selectors. The paragraph explores different programming languages' approaches to these issues, including the use of special words, parentheses, and boolean types. It also touches on the impact of these design choices on language readability and flexibility, and how certain languages like Perl and Python use unique methods like braces and indentation to define clauses.
🔄 Ambiguity in Nested Selection Statements
This paragraph examines the problem of ambiguity in nested selection statements, particularly in languages like Java, where static semantic rules dictate that an 'else' clause matches the nearest 'if'. The potential confusion this can cause is highlighted, and the use of compound statements with braces to disambiguate is explained. The paragraph also covers how languages like Perl, C, and C# handle this issue by requiring all 'then' and 'else' clauses to be compound statements, thus eliminating ambiguity. The impact of these approaches on programming language evaluation criteria is discussed.
📚 Disambiguation Techniques in Programming Languages
The fourth paragraph continues the discussion on disambiguating nested selection statements, showcasing how different programming languages approach this issue. It describes Ruby's use of the 'end' keyword to clearly mark the end of selection statements, preventing ambiguity. The paragraph also contrasts this with Python's reliance on indentation to match 'if' and 'else' clauses, which inherently avoids ambiguity. The importance of the 'else' clause in languages like ML, F#, and Lisp, where selection statements can return values, is emphasized, and the requirement for an 'else' clause in these contexts is explained.
🔄 Multiple Way Selection Statements Design
The fifth paragraph shifts focus to multiple way selection statements, commonly known as 'switch' or 'case' statements. It outlines the design issues related to these statements, including the form and type of the control expression, the specification of selectable segments, execution restrictions, case value specification, and handling of unrepresented expression values. Practical examples from C, C++, Java, and JavaScript illustrate how these languages implement 'switch' statements, with a focus on their syntax and semantics. The paragraph also discusses the impact of design decisions on language reliability and evaluation criteria.
🎛️ C# and Ruby's Multiple Way Selection Statements
This paragraph compares C# and Ruby's implementations of multiple way selection statements. It highlights C#'s semantic rule requiring unconditional branches to prevent accidental execution of multiple segments and its allowance of strings as case constants, which is not possible in C. The paragraph also explains Ruby's 'case' expressions, which can function as expressions returning results and can be used in two forms: one with only 'when' conditions and another with a case value and 'when' values. The impact of these features on the programming language evaluation criteria is discussed, inviting the viewer to consider the effects on reliability and expressiveness.
🔄 Boolean Multiple-Way Selection as an Alternative to Nested If-Else
The final paragraph discusses boolean multiple-way selection statements as an alternative to nested if-else statements, which can sometimes be less readable. It provides an example of such a structure in Python, illustrating how 'if', 'elif', and 'else' keywords are used to create a sequence of conditions and associated statements. The paragraph concludes the chapter's discussion on selection statements and teases the next lecture's topics, which will include iterative statements, unconditional branching, and guarded commands.
Mindmap
Keywords
💡Statement Level Control Structures
💡Selection Statements
💡Two-Way Selection Statements
💡Control Expression
💡Nested Selectors
💡Multiple Entry Points
💡Flowchart Represented Algorithms
💡Compound Statements
💡Indentation
💡Switch Statements
💡Case Expressions
💡Boolean Multiple-Way Selection Statements
Highlights
Introduction to statement level control structures in programming languages.
Discussion of control within expressions and among program units, with a focus on control flow among program statements.
Historical context of FORTRAN and the reliance on low-level control structures like go-to statements.
1960s research indicating that flowchart algorithms can be represented with two-way selection and pre-test loops, reducing the need for unconditional branches.
Definition and design issues of control structures, including the debate over multiple entry points and the use of go-to statements.
Exploration of selection statements, including two-way and multiple way selectors, and their significance in programming.
Design issues of two-way selection statements, such as the form and type of the control expression.
Different approaches to clause specification in modern programming languages, including single and compound statements.
The unique use of indentation in Python for differentiating clauses within selection statements.
Ambiguity in nested selection statements and how languages like Java disambiguate with static semantic rules.
Use of compound statements to eliminate ambiguity in nested selection statements, as seen in C, C++, and C#.
Perl's requirement for all clauses to be compound, even if they contain a single statement.
Ruby's approach to disambiguation using a special word to mark the end of a selection statement.
Python's use of indentation to eliminate ambiguity in nested selection statements.
Discussion on the use of selection statements as expressions in languages like ML, F#, and Lisp, allowing for conditional assignment.
Introduction to multiple way selection statements, also known as switch or case statements.
Design issues of multiple way selection statements, including the form and type of control expressions and the syntax for case values.
C, C++, Java, and JavaScript's use of switch statements for multiple way selection, including the use of case and default clauses.
C#'s semantic rule requiring unconditional branches at the end of each selectable segment to prevent implicit execution.
Ruby's case expressions that can return a result, offering an alternative to traditional switch statements.
Python's alternative approach to multiple selections using if statements for better readability.
Transcripts
in the previous two lectures we covered
chapter seven which deals with
expressions and assignment statements
in this lecture we will begin with the
first part of our discussion on chapter
eight
which deals with statement level control
structures
this is an overview of the topics that
we'll be discussing in today's lecture
we'll start with an introduction to
statement level control structures
and then we'll move on to selection
statements
this is quite a substantial proportion
of the chapters material and therefore
we'll be spending quite a lot of time on
it
now within programming languages there
are various levels of control that we
can discuss
so firstly we have control within
expressions here things like the
president's and associativity rules come
into play and we discussed these in the
previous chapter
we also have control flow among program
units essentially sub-programs or what
you'll know as methods or functions and
we'll discuss this in the next chapter
chapter 9.
in this chapter we'll be discussing
control flow among program statements
now as we saw in chapter 2 fortune 1 was
specifically designed to work with the
ibm 704 hardware and what this meant was
that the control statements were based
directly on the hardware and were
therefore very low level
what this meant was that the control
structures that were supported were very
specific to the hardware
and didn't function
in a similar fashion to what we used
today
what it also meant was that there was a
heavy reliance on jumps or what you
would understand as go-to statements
so after the development of fortran
there was a lot of research and
arguments that took place in the 1960s
as to what the best approach was to use
for control statements
and one important result of this was
that all flowchart represented
algorithms can be coded with only
two-way selection statements and
pre-test logical loops
two-way selections are if else
statements and pretest logical loops are
while loops
so what this thing means is that
unconditional branching statements for
example jumps or go to statements
are unnecessary
now a control structure is a control
statement such as an if statement or a
while statement and then also the
statements whose execution the control
structure controls
now there's one design issue for all
control structures and that is should
the control structure in question have
multiple entry points
now it's only possible to achieve this
through the use of go to statements and
statement labels where a go to statement
will jump execution to a particular
point in the program that is labeled
with the statement label
now in general support for go to
statements and therefore multiple entry
points into control structures
is considered to add little flexibility
relative to the decreased readability
that they will introduce
now a selection statement provides a
choice between two or more execution
parts where this choice is exclusive in
other words execution can only follow
one of the selection paths out of a set
now there are two general categories of
selection statements namely two-way
selectors and multiple way selectors and
we'll be looking at each of these
separately
so let's start with two-way selection
statements or two-way selectors over
here we have the general form of a
two-way selection statement
we can see that we have a special word
usually
if which introduces the statement
and following which we have a control
expression and this control expression
will be evaluated like a true false or
boolean value it doesn't necessarily
have to have a boolean type though as
we'll see in a moment
then we have a clause that is executed
in the then portion if the control
expression's value is interpreted as
true and if the control expressions
value is interpreted as a false then we
execute the else clause
so the three design issues associated
with two-way selection statements
firstly related to the control
expression what is its form and type
then related to the then and else
clauses how are these clauses specified
and then in the third place how should
nested selectors be disambiguated and
we'll look at each of these design
issues in turn
let's start by looking at the first of
the three design issues
that relate to the control expression
both the form of the control expression
and the type of the control expression
so if we are looking at the form of the
controlled expression we need to
consider how the then clause is
introduced and there are two approaches
to this
so firstly we can use a special word
something like then
to introduce the then clause
notice that in this case there are no
parentheses surrounding the condition
the second approach is that we can
surround the control expression with
opening and closing parentheses
now what's important to note here is
that whichever approach we select for a
programming language
the condition needs to be delimited so
in the first case the condition is
delimited by the special words if and
then
in the second case the control
expression is delimited by opening
and closing
parentheses
so now if we move on to the type of the
control expression
we see that in c89 and c99 as well as
python and c plus the control expression
can be arithmetic in nature and in this
case an integer condition will be
interpreted as a boolean value so in
other words a zero value will be
interpreted as false and a non-zero
value will be interpreted as true
however in most other modern high level
programming languages the control
expression must be of a boolean
type moving on to the second design
issue related to
two-way selectors
we have the form that the clauses can
take
so then and else clauses in modern
programming languages can either be a
single statement
or they can be compound statements where
a compound statement consists of
multiple single statements
now in general in most situations a
compound statement will be delimited in
some way possibly with opening and
closing braces
or possibly special words at the
beginning and end of the compound
statements usually single statements are
not delimited
now perl is a little bit different in
perl all clauses must be delimited by
braces so in other words they have to be
compound even if they consist of only
one single statement
in fortune 95 ada python and ruby
clauses are considered to be statement
sequences where the sequence can have
one or more statements within it
so a selection statement in these
languages will end with a reserved word
something like end or end if for example
python once again uses a fairly
different approach to other high-level
programming languages in that it uses
indentation to differentiate clauses
so here we have an example of a two-way
selector
in python this only has a then clause
and we can identify the then clause
because it's this indented portion over
here which is indented further
than the if and the condition are
so
we can use then either spaces or tabs
for this indentation however we can't
mix both together and we must use the
same approach throughout our program
so what i would like you to do at this
point is to pause the video
and try to determine how this would
affect the language evaluation criteria
particularly in a negative way
finally let's move on to the third
design issue related to two-way
selection statements
so over here we have some example java
code
and this involves two if statements
so we have our first if with a condition
that tests where the sum is equivalent
to zero
then we have a second if with its
condition that tests to see where the
count is equivalent to zero
then we have a then clause which
contains an assignment where xero is
assigned to the variable result and we
have an else clause which performs also
an assignment but this time of a value
one to the variable result
so the question is then which if does
the else clause match to
now there are various ways that this can
be approached in order to disambiguate
which if the else matches to with the
red first if or the second if
now the approach that java uses is that
it has a static semantic rule which
specifies that every else matches with
the nearest if
so in other words what this means then
is that this else clause will actually
match with the second if or the inner if
rather than the outer one despite what
the indentation appears to indicate to
us
so this can be fairly confusing and what
i would like you to do at this point is
once again pause the video and try to
answer how this kind of ambiguity and
the use of static semantic rules could
affect the programming language
evaluation criteria we've been using
through this course
now if we are using a static semantic
rule in order to disambiguate nested
selection statements then we can force
alternative semantics through the use of
compound statements and that's exactly
what we've done in this example over
here
so what we have done is for the outer if
statement we have created a
compound statement as the then clause
and that encapsulates the nested if
statement with its then clause so we can
see the beginning
and the end of the compound statement
which is delimited by means of braces
so what this means then is that the else
clause over here will now match the
outer if statement and its condition
the solution is also used in c c plus
and the c sharp programming languages
bill's approach to disambiguating nested
selection statements relies on the fact
that it requires all thin and else
clauses to be compound
so even if a clause contains only a
single statement that single statement
must be delimited as a compound
statement
and this then eliminates any ambiguity
so here we see an example in perl
of the same nested if
statements that we saw in our java
example previously
we can see that this is very much like
the second java example that we looked
at where we matched the else clause to
the then clause of the outer if
statement once again we have a compound
then clause
for our outer if which the else then
matches to
the only difference here is that we can
see that the single statements which are
associated with the then clause of the
nested if as well as the else clause of
the out if are also compound in this
example and we can see this because they
are delimited by means of braces
ruby's approach to disambiguating nested
selectors relies on the fact that it
uses a special word to mark the end of a
selection statement and the special word
in the case of ruby is end
so this also then eliminates any
possible ambiguity
and we can see our previous example
written in ruby over here so notice that
we have special words that are used
throughout
for instance if we look at our outer
two-way selection statement then we have
the if special word
then which introduces the then clause
else which ends the then clause and
begins the else clause and then finally
end which denotes the end of the two-way
selection statement
so we know then that this else over here
must match with the outer if because the
inner if has already ended with the end
special word over here this means that
the else that follows can't then match
with the nested if statement because
that has already been ended and
therefore must match with the outer if
statement
so what i would like you to do at this
point is to pause the video and try to
answer how ruby and to a lesser extent
pearl's approach to disambiguating
nested selection statements affects the
programming language evaluation criteria
we've been using through this course
our final example related to how a
programming language can disambiguate
nested selection statements is in python
so as we've seen previously python uses
indentation in order to identify then
and else clauses within a two-way
selection statement and this indentation
also eliminates any ambiguity
the reason for this is that we can very
easily identify which then clause and
else matches to because they will be
indented to the same level so we can see
this in this example over here where we
can very easily see that the else clause
must match with the then of the outer if
statement because these are indented to
exactly the same level
the last detail that we need to discuss
related to two-way selection statements
is the use of selectors as expressions
so this is the case in ml f-sharp and
lisp
and in these languages the selection
statement is actually an expression so
what this means is that the selection
statement can return a value
so that means that the following code is
legal in if shop here we can see that
we're using a late in order to perform
an assignment to a name
y in this example and we are assigning
to it
our if expression over here which is a
two-way selection statement that is used
as an expression
so what this means is that our condition
is tested we check to see whether x is
greater than zero
if it is then our then clause simply
contains x in this case so this means
x's value will then be associated
or bound to
this
name y
however if x is not greater than zero in
other words it's zero or it is less than
zero
then the else clause will be chosen and
in this case that is 2 multiplied by x
so in that case 2 multiplied by x will
be computed and that value will be bound
to the name y
so if the if expression returns a value
then there must be an else clause we are
not allowed to leave out the else clause
so what i would like you to do at this
point is to pause the video and try to
answer why the else clause is required
in this case
when i move on to the second kind of
selection statement that exists namely
the multiple way selection statement
so multiple way selection statements
allow for the selection of only one out
of a larger set of either single
statements or groups of statements and
you'll know these as switch or case
statements
so there are five design issues related
to multiple way selection statements
firstly what is the form and type of the
control expression and this is similar
to the first design issue that we
discussed in relation to two-way
selection statements
secondly how are the selectable segments
specified and this relates to the syntax
that is used for each of the individual
cases
then in the third place is execution
through the structure restricted to
include only one selectable segment
or can execution include multiple
selectable segments together
one following the other
then fourthly how are the case values
specified and again this is a question
of the syntax that will be used
and then finally are unrepresented
expression values handled in some way
in order to handle an unrepresented
expression value we would have to have
some sort of default segment
now we'll be looking at these design
issues in relation to practical examples
of how various programming languages
deal with multiple ways selection
statements
so the first that we'll look at is used
in c c plus plus java and javascript and
you will be very familiar with this
approach which we see in this example
over here
the multiple way selection is introduced
by the special word switch and this is
why we very often refer to these
multiple way selections as switch
statements
following the switch special word we
have the control expression which is
delimited by means of parentheses and
then we have the body of our switch
which is delimited by an opening brace
and a closing brace
inside the switch we have a series of
cases we can have any number of cases
each one introduced by the special word
case
and we then have a constant expression
followed by a colon and then a
selectable segment the selectable
segment can either be a single statement
or a series of statements
we then have following the series of
cases an optional default clause which
is introduced by the default special
word also then followed by a colon and
then a segment associated with that
which of course can be a single
statement or a series of statements
following one another
so the semantics then of how the switch
statement would be evaluated is that the
control expression is compared to the
constants one by one from top to bottom
the first
case then that
indicates a match between the control
expression and its constant expression
will be selected and then the
corresponding selectable segment will be
executed
here we have the design decisions that
were made for c's switch statement
so firstly the control expression and
the constant expressions can be either
integers characters or enumerations
notice that each of these can be
interpreted as whole integer values
secondly selectable segments can be
either statement sequences or compound
statements in other words blocks and of
course this also includes single
statements
then thirdly control can flow through
multiple segments
so
there's an explicit unconditional branch
or a break that is required at the end
of a selectable segment otherwise
control will flow to the next segment
and control can flow through multiple
segments it can even flow all the way
down to the default segment if there are
no breaks that appear within the switch
statement
finally there is a default clause for
unrepresented values
and if this default clause is omitted
but the control expression then matches
no constant expressions then the entire
selection statement will simply do
nothing
now c sharp has a fairly similar syntax
to c when it comes to multiple way
selection statements
however it differs from c in two
important ways
so firstly c sharp has a semantic rule
that disallows the implicit execution of
more than one segment in other words it
is not possible to accidentally have
control run from one case on to the next
case
and c-sharp achieves this by requiring
that each selectable segment must end
with an unconditional branch where the
unconditional branch is either a go-to
or a break
so the semantics here then for a break
would be exactly the same as in c when a
break is encountered then the case
is terminated and execution moves to the
end of the switch statement
in the case of the go to the go to must
be paired with a case label and in that
case execution will then jump to the
appropriate case and execution will
continue from there
there's only one situation in which a
go-to or break is not required and that
is when the selectable segment is empty
in that case control will then
automatically flow to the next case
statement
so what i would like you to do at this
point is to pause the video and try to
explain what effect this approach has on
the reliability of c sharp
secondly c sharp differs from c
in that both the control expression and
the case constants can be strings which
of course as we saw on the previous
slide is not possible in c
again i'd like you to pause the video at
this point and try to answer what effect
this has on the programming language
evaluation criteria
ruby's multiple way selections are
referred to as case expressions and the
fact that they are expressions means
that the case can return a result now
there are two forms of these case
expressions and the first uses only when
conditions in other words there is no
control expression present
now this kind of case expression works
like a sequence of everything else
statements and we can see an example of
this over here
so here we have our case expression
which is introduced for the special word
case and ends with a special word end
and we can see that there is no control
expression present so we just have then
within the case series of when
and
final else segment
so what happens then when the case is
encountered
is that each of the conditions will be
evaluated one at a time and whichever
one matches first will then have its
corresponding segment executed
so if yeah mod 400 is equivalent to zero
then the entire case will evaluate to
true
if year mod 100 is equivalent to zero
then the entire case will evaluate to
false
and finally if we reach the else portion
over here then we evaluate year mod 4
equivalent to 0 and depending on whether
this is true or false the entire case
will evaluate to true or false
and whichever
mode of execution is followed the true
or the false value that is produced will
then be assigned to leap in this case
which is a variable
and this is because the entire case is
dealt with as an expression and
therefore can return a result which is
used in the assignment
the second form of ruby's case
expressions uses a case value as a
control expression and also has when
values in this case expression works
much more like a traditional switch
statement that we've looked at
previously
so here we have an example of the use of
this kind of case expression we can see
once again that we are using the value
of the case expression and assigning
that to a variable named vowel
here we have our case value which is a
variable inval and then inside the case
we have a series of wins followed by an
else so the way that this would work is
that the case value inval would be
compared to each of the when values in
turn and the first one that matches will
then have its statement evaluated which
becomes the value for the entire case
and that will then be assigned to val
so in other words if inval has a value
of negative one
then the entire case evaluates to the
value of threshold minus one which will
then be assigned to the valve variable
if inval has a value of 0 then threshold
will be assigned to val and if inval has
a value of 1 then the value of threshold
plus 1 will be assigned to val
finally if we have a value for inval
that doesn't match any of the win values
then the else will be evaluated in which
case we have an error code that is
stored in this variable over here
and that will then be assigned to val
we'll now take a quick look at multiple
selections using an if statement so
these multiple selectors are boolean
multiple-way selection statements and
there are an alternative to nested
two-way selection statements in other
words nested if then else statements
where these nested if-then-else
statements may be poorly readable
so here is an example of this kind of
structure in python and you can see that
it follows the same form as the first
form of ruby's case expressions
so we have then an if special word and
that introduces our initial condition
which then has a statement associated
with it there may of course be multiple
statements as well then we have the
special word el if and this is
equivalent to an else and an if
following the else we then have a second
condition associated with it and a
second statement or set of statements
that will be executed if that condition
is met and we can have as many elevens
as we want to as well as an else right
at the end
all right so that concludes our
discussion on this chapter
in the next lecture we'll be finishing
off the discussion on this chapter and
there we will be discussing iterative
statements unconditional branching and
guarded commands
5.0 / 5 (0 votes)