This document discusses principles of sequence control in programming languages. It covers expressions, assignment statements, selection statements like if/else and switch/case, and iterative statements like for, while, and loops controlled by data structures. It provides examples of how these concepts are implemented in different languages like C, Pascal, and C#. Unconditional branching with goto is also discussed, noting that while powerful it can hurt readability so most modern languages avoid or restrict it.
Complete C++ programming Language CourseVivek chan
This is the Complete course of C++ Programming Language for Beginners. All Topics of C++ programming Language are covered in this single power point presentation.
Visit: www.cyberlabzone.com
The root of all modern language is ALGOL (Algorithmic Language), introduced in the early 1969s. ALGOL was the first computer language to use a block structure. In 1967, Martin Richards developed a language called BCPL (Basic Combined Programming Language) primarily for writing system software. In 1970, Ken Thompson created a language using main features of BCPL and called it simply B. B was used to create early version of UNIX operating system at Bell Laboratories. C was evolved from ALGOL, BCPL and B by Dennis Ritchie at AT & T’s Bell Laboratories in 1972 for use on the UNIX operating system. It has since spread to many other operating systems, and is now one of the most widely used programming languages.
Complete C++ programming Language CourseVivek chan
This is the Complete course of C++ Programming Language for Beginners. All Topics of C++ programming Language are covered in this single power point presentation.
Visit: www.cyberlabzone.com
The root of all modern language is ALGOL (Algorithmic Language), introduced in the early 1969s. ALGOL was the first computer language to use a block structure. In 1967, Martin Richards developed a language called BCPL (Basic Combined Programming Language) primarily for writing system software. In 1970, Ken Thompson created a language using main features of BCPL and called it simply B. B was used to create early version of UNIX operating system at Bell Laboratories. C was evolved from ALGOL, BCPL and B by Dennis Ritchie at AT & T’s Bell Laboratories in 1972 for use on the UNIX operating system. It has since spread to many other operating systems, and is now one of the most widely used programming languages.
C is a general-purpose high level language that was originally developed by Dennis Ritchie for the Unix operating system. It was first implemented on the Digital Equipment Corporation PDP-11 computer in 1972.
Esoft Metro Campus - Programming with C++
(Template - Virtusa Corporate)
Contents:
Overview of C++ Language
C++ Program Structure
C++ Basic Syntax
Primitive Built-in types in C++
Variable types
typedef Declarations
Enumerated Types
Variable Scope
Constants/Literals
Storage Classes
Operators
Control Constructs
Functions
Math Operations in C++
Arrays
Multi-dimensional Arrays
Strings
C++ Pointers
References
Date and Time
Structures
Basic Input / Output
Classes and Objects
Inheritance
Overloading
Polymorphism
Interfaces
Files and Streams
Exception Handling
Dynamic Memory
Namespaces
Templates
Preprocessor
Multithreading
C is a general-purpose high level language that was originally developed by Dennis Ritchie for the Unix operating system. It was first implemented on the Digital Equipment Corporation PDP-11 computer in 1972.
Esoft Metro Campus - Programming with C++
(Template - Virtusa Corporate)
Contents:
Overview of C++ Language
C++ Program Structure
C++ Basic Syntax
Primitive Built-in types in C++
Variable types
typedef Declarations
Enumerated Types
Variable Scope
Constants/Literals
Storage Classes
Operators
Control Constructs
Functions
Math Operations in C++
Arrays
Multi-dimensional Arrays
Strings
C++ Pointers
References
Date and Time
Structures
Basic Input / Output
Classes and Objects
Inheritance
Overloading
Polymorphism
Interfaces
Files and Streams
Exception Handling
Dynamic Memory
Namespaces
Templates
Preprocessor
Multithreading
This presentation of ROBO INDIA comprises all of the elements that must be known to learn the programming language C.
This ppt also explains all these topics in details.
We welcome all you views and queries. Please write us, we are found at-
website: http://roboindia.com
mail: info@roboindia.com
How to build a news website use CMS wordpressbaran19901990
This tutorial wil show you, how to build a news website use CMS Wordpress step by step. From basic to advantage. I think that this tutorial is amazing and very basic for newbie.
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdfFlorence Consulting
Quattordicesimo Meetup di Milano, tenutosi a Milano il 23 Maggio 2024 dalle ore 17:00 alle ore 18:30 in presenza e da remoto.
Abbiamo parlato di come Axpo Italia S.p.A. ha ridotto il technical debt migrando le proprie APIs da Mule 3.9 a Mule 4.4 passando anche da on-premises a CloudHub 1.0.
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBrad Spiegel Macon GA
Brad Spiegel Macon GA’s journey exemplifies the profound impact that one individual can have on their community. Through his unwavering dedication to digital inclusion, he’s not only bridging the gap in Macon but also setting an example for others to follow.
1.Wireless Communication System_Wireless communication is a broad term that i...JeyaPerumal1
Wireless communication involves the transmission of information over a distance without the help of wires, cables or any other forms of electrical conductors.
Wireless communication is a broad term that incorporates all procedures and forms of connecting and communicating between two or more devices using a wireless signal through wireless communication technologies and devices.
Features of Wireless Communication
The evolution of wireless technology has brought many advancements with its effective features.
The transmitted distance can be anywhere between a few meters (for example, a television's remote control) and thousands of kilometers (for example, radio communication).
Wireless communication can be used for cellular telephony, wireless access to the internet, wireless home networking, and so on.
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC
Ellisha Heppner, Grant Management Lead, presented an update on APNIC Foundation to the PNG DNS Forum held from 6 to 10 May, 2024 in Port Moresby, Papua New Guinea.
This 7-second Brain Wave Ritual Attracts Money To You.!nirahealhty
Discover the power of a simple 7-second brain wave ritual that can attract wealth and abundance into your life. By tapping into specific brain frequencies, this technique helps you manifest financial success effortlessly. Ready to transform your financial future? Try this powerful ritual and start attracting money today!
3. Levels of Control Flow
•Within expressions
•Among program units
•Among program statements
4. Expressions
•An expression is a syntactic entity whose evaluation either:
–produces a value
–fails to terminate undefined
•Examples
4 + 3 * 2
(a + b) * (c - a)
(b != 0) ? (a/b) : 0
5. Expression Syntax
•Expressions have functional composition nature
•Common syntax
–Infix
–Prefix
–Postfix
(a + b) * (c – a)
*
+
–
a
b
c
a
6. Infix Notation
(a + b) * (c – a)
•Good for binary operators
•Used in most imperative programming language
•More than two operands?
(b != 0) ? (a/b) : 0
•Smalltalk:
myBox displayOn: myScreen at: 100@50
7. Precedence
3 + 4 * 5 = 23, not 35
•Evaluation priorities in mathematics
•Programming languages define their own precedence levels based on mathematics
•A bit different precedence rules among languages can be confusing
9. Associativity
•If operators have the same level of precedence, then apply associativity rules
•Mostly left-to-right, except exponentiation operator
•An expression contains only one operator
–Mathematics: associative
–Computer: optimization but potential problems
1020 * 10-20 * 10-20
10. Parentheses
•Alter the precedence and associativity
(A + B) * C
•Using parentheses, a language can even omit precedence and associativity rules
–APL
•Advantage: simple
•Disadvantage: writability and readability
11. Conditional Expressions
if (count == 0) average = 0; else average = sum / count;
average = (count == 0) ? 0 : sum / count;
•C-based languages, Perl, JavaScript, Ruby
12. Prefix Notation
* + a b – c a
(* (+ a b) (– c a))
•Derived from mathematical function f(x,y)
•Parentheses and precedence is no required, provided the -arity of operator is known
•Mostly see in unary operators
•LISP:
(append a b c my_list)
13. Postfix Notation
a b + c a – *
•Reverse Polish
•Common usage: factorial operator (5!)
•Used in intermediate code by some compilers
•PostScript:
(Hello World!) show
14. Operand Evaluation Order
•C program
int a = 5; int fun1() { a = 17; return 3; } void main() { a = a + fun1();
}
•Reason: Side effect!!!
What is the value of a?
15. Undefined Operands
•Eager evaluation:
–First evaluate all operands
–Then operators
–How about a == 0 ? b : b/a
•Lazy evaluation:
–Pass the un-evaluated operands to the operator
–Operator decide which operands are required
–Much more expensive than eager
•Lazy for conditional, eager for the rest
*
+
–
a
b
c
a
16. Short-Circuit Evaluation
(a == 0) || (b/a > 2)
•If the first operand is evaluated as true, the second will be short-circuited
•Otherwise, “divide by zero”
•How about (a > b) || (b++ / 3) ?
•Some languages provide two sets of boolean operators: short- and non short-circuit
–Ada: “and”, “or” versus “and then”, “or else”
17. Statements
•An expression is a syntactic entity whose evaluation:
–does not return a value, but
–have side effect
•Examples:
a = 5;
print "pippo"
begin...end
18. Assignment Statements
expr1 OpAss expr2
•Example: Pascal
X := Y
•Evaluate left or right first is up to implementers
Address?
Value?
5
5
19. Assignment Statements
•C-based languages consider assignment as an expression
while ((ch = getchar()) != EOF) { . . . }
•Introduce compound and unary assignment operators (+=, -=, ++, --)
–Increasing code legibility
–Avoiding unforeseen side effects
20. Control Structures
•Control statements
–Selecting among alternative control flow paths
–Causing the repeated execution of sequences of statements
•Control structure is a control statement and the collection of its controlled statements
21. Two-way Selection
if control_expression then clause else clause
•Proved to be fundamental and essential parts of all programming languages
22. Dangling else
if (sum == 0) if (count == 0) result = 0; else result = 1;
•Solution: including block in every cases
•Not all languages have this problem
–Fortran 95, Ada, Ruby: use a special word to end the statement
–Python: indentation matters
23. Multiple-Selection
•Allows the selection of one of any number of statements or statement groups
•Perl, Python: don’t have this
•Issues:
–Type of selector expression?
–How are selectable segments specified?
–Execute only one segment or multiple segments?
–How are case values specified?
–What if values fall out of selectable segments?
24. Case Study: C
switch (index) {
case 1:
case 3: odd += 1;
sumodd += index;
break;
case 2:
case 4: even += 1;
sumeven += index;
break;
default: printf(“Error in switch”).
}
integer
- Stmt sequences - Blocks
Multiple segments
exited by break
for unrepresented values
exact value
25. Case Study: Pascal
case exp of 1: clause_A 2, 7: clause_B 3..5: clause_C 10: clause_D else clause_E end
Integer or character
- Single statements
- Blocks
Only one segment
for unrepresented values
multiple values, subrange
26. Iterative Statements
•Cause a statement or collection of statements to be executed zero, one or more times
•Essential for the power of the computer
–Programs would be huge and inflexible
–Large amounts of time to write
–Mammoth amounts of memory to store
•Design questions:
–How is iteration controlled?
•Logic, counting
–Where should the control appear in the loop?
•Pretest and posttest
28. Case Study: Algol-based
General Form
for i:=first to last by step
do
loop body
end
Semantic
[define i]
[define first_save]
[define end_save]
i = start_save
loop:
if i > end_save goto out
[loop body]
i := i + step
goto loop
out:
[undefine i]
constant
Know number of loops before looping
29. Case Study: C
General Form
for (expr1; expr2; expr3)
loop body
Semantic
expr_1
loop:
if expr_2 = 0 goto out
[loop body]
expr_3
goto loop
out: . . .
Can be infinite loop
30. Logically Controlled Loops
•Repeat based on Boolean expression rather than a counter
•Are more general than counter-controlled
•Design issues:
–Should the control be pretest or posttest?
–Should the logically controlled loop be a special form of a counting loop or a separate statement?
31. Case Study: C
Forms
while (ctrl_expr)
loop body
do
loop body
while (ctrl_expr)
Semantics
loop:
if ctrl_expr is false goto out
[loop body]
goto loop
out: . . .
loop:
[loop body]
if ctrl_expr is true goto loop
32. User-Located Loop Control
•Programmer can choose a location for loop control rather than top or bottom
•Simple design: infinite loops but include user- located loop exits
•Languages have exit statements: break and continue
•A need for restricted goto statement
33. Case Study: C
while (sum < 1000) {
getnext(value);
if (value < 0) break;
sum += value;
}
•What if we replace break by continue?
34. Iteration Based on Data Structures
•Rather than have a counter or Boolean expression, these loops are controlled by the number of elements in a data structure
•Iterator:
–Is called at the beginning of each iteration
–Returns an element each time it is called in some specific order
•Pre-defined or user-defined iterator
35. Case Study: C#
String[] strList = {"Bob", "Carol", "Ted"}:
. . .
foreach (String name in strList)
Console.WriteLine("Name: {0}", name);
36. Unconditional Branching
•Unconditional branch, or goto, is the most powerful statement for controlling the flow of execution of a program’s statements
•Dangerous: difficult to read, as the result, highly unreliable and costly to maintain
•Structured programming: say no to goto
•Java, Python, Ruby: no goto
•It still exists in form of loop exit, but they are severely restricted gotos.
37. Conclusions
•Expressions
•Operator precedence and associativity
•Side effects
•Various forms of assignment
•Variety of statement-level structures
•Choice of control statements beyond selection and logical pretest loops is a trade-off between language size and writability