0% found this document useful (0 votes)
3 views

Lecture 1_introduction to Programming

The document provides an introduction to programming, explaining key concepts such as computer programs, programming languages, syntax, statements, and expressions. It defines computer programming as the process of writing instructions for computers to execute tasks and highlights the importance of following specific syntax for successful code execution. Additionally, it discusses various types of statements and expressions used in programming, illustrating their roles with examples.

Uploaded by

lezileonesmo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lecture 1_introduction to Programming

The document provides an introduction to programming, explaining key concepts such as computer programs, programming languages, syntax, statements, and expressions. It defines computer programming as the process of writing instructions for computers to execute tasks and highlights the importance of following specific syntax for successful code execution. Additionally, it discusses various types of statements and expressions used in programming, illustrating their roles with examples.

Uploaded by

lezileonesmo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

INTRODUCTION TO

PROGRAMMING
Msangi, R.I
OUTLINE

● Overview
● Computer program
● Computer programming language
● Program syntax
● Statements
● Expressions
● Blocks
OVERVIEW
● Computer programming is The process of designing and writing
instructions (codes) that a computer can execute to perform specific
tasks or solve problems. It involves creating algorithms and translating
them into a programming language..
● Coding: This refers to the process of writing code in a specific
programming language. It involves translating algorithms and logic into
a syntax that a computer can understand. Coding is typically seen as
a more technical and focused activity.
● Computer programs are written using a computer programming
language
COMPUTER PROGRAM
A computer program is a sequence of instructions written using a
computer programming language to perform a specified task by the
computer
The two important terms that we have used in the above definition
are:-

● Sequence of instructions
● Computer Programming language
COMPUTER PROGRAM

● Assuming you want directions to go to Mlimani City


Shopping Mall
● There might be a banner with instructions like:-
● Go straight
● Drive half a kilometer
● Take left
● Drive around one kilometer
● Search for the mall at your right side
COMPUTER PROGRAM

● The above sequence of instructions is actually a Human


Program written in English Language, which instructs on how
to find Mlimani City Shopping Mall from a given starting
point.
● This same sequence could be given in Spanish, Hindi,
Arabic, Swahili, or any other human language provided the
person seeking direction knows any of these languages
COMPUTER PROGRAM

● Computer programs are also known as codes


● In language and communications, a code is a set of rules
that governs how communication is carried out.
● In a context of programming, a code is a set of instructions
that tells a computer what actions to take.
● Computer programs (codes) are written using a
programming language.
COMPUTER PROGRAM LANGUAGE

● A programming language is a computer language


programmers use to develop software programs, scripts, or
other sets of instructions for computers to execute.
● A programmer is a person who writes computer programs.
● There are hundreds of programming languages in use today,
and many are yet to come
COMPUTER PROGRAM LANGUAGE

● Most programming languages share some similarities,


however, each programming language has its own syntax.
● When writing a program in a particular language, a
programmer must follow the syntax of that specific language.
● A program that syntatically is not correct cannot run or give
intended results.
● Most programming languages will issue an error if not written
in a correct syntax.
COMPUTER PROGRAM LANGUAGE

● Some of the most popular programming languages include


Java, C, C++, Python, PHP, Javascript, ASP, Perl, C#, Julia,
Ruby, Visual Basic, Objective C, S, Go, R, VBA, D, Swift etc.
● Choosing a programming language depends on many
factors including speed, security etc.

PROGRAM LANGUAGE SYNTAX

● Syntax is what differentiates one programming language


from the other.
● The syntax of a programming language is a set of rules that
define which arrangements of symbols comprise structurally
legal programs.
● They are the rules that define the structure of the language.
● Syntax means the rules that control the symbols,
punctuation, and words of a programming language.
PROGRAM LANGUAGE SYNTAX

● Without syntax, the meaning or semantics of a language


may be difficult to understand.
● Applying basic syntax results into a sentence.
● So, a computer program is a collection of one or more
sentences that defines an action to be taken by a computer
or a software.
PROGRAM STATEMENTS

● A statement is a complete single unit of code for execution.


● Statements are fragments of a program that are executed in
sequence.
○ Example, the body of a function is a sequence of one or more
statements
● Statements are likely equivalent to sentences in a natural
language.
● A program can have one or more statements that collectively
define what action should be taken by a computer to perform a
specific action.
PROGRAM STATEMENTS

● A statement can be any of the following


○ Declaration statements
○ Assignment statements
○ Expression statements
○ Iteration statements
○ Flow control statements
○ Method/Function call statements
PROGRAM STATEMENTS

● Declaration statements
○ Defines variables, functions/methods and objects
○ With declaration statements, variables, functions and
objects are created into being
○ E.g.
■ int age;
○ The above statement has created a variable called age
which will hold integer values
PROGRAM STATEMENTS

● Assignment statements
○ Assigns a value to a to a program variable
○ E.g.
■ age = 17;
● The above statement assigns the value 17 to a
variable age.
■ float height = 1.65;
● The above statement creates a variable height of
type float and assigns a value 1.65 to it.
PROGRAM STATEMENTS

● Expression statements
○ A statement that evaluates into a value
○ E.g.
■ z=x+y;
○ The above statement returns the sum of x and y and
assigns it to the variable z.
PROGRAM STATEMENTS
● Iteration statements
○ Iteration statements instruct the program to repeat a series of statements
a specified number of times depending on some set conditions
○ E.g.
while(stop==true){
/* code to be executed */
}
● The above statement executes the block of code within {...} as long as the
value of stop is true
PROGRAM STATEMENTS
● Decision statements
○ Decision statements decides the order of execution of statements
○ Statements are executed depending on some set conditions.
○ E.g.

if(age>=18){

print(“Adult”);

}else{

print(“Still a boy”);

○ The above flow control statement Displays ‘Adult’ if age is greater or equal to 18, otherwise
it displays ‘Still a boy’.
PROGRAM STATEMENTS

● Method/Function call statements


○ Method/function call statement transfers program control
to the called function (invoked method).
○ After the called function (invoked method) finishes
execution of its statements, immediately program control
is transferred back to the function call statement and
execution continues with the next statement after the
function call.
○ E.g. addNumbers(24, 34);
EXPRESSIONS

● An expression is a series of variables, operators, and


method calls (constructed according to the syntax of the
language) that evaluates to a single value.
EXPRESSIONS

● You can write compound expressions by combining


expressions as long as the types required by all of the
operators involved in the compound expression are correct.
EXPRESSIONS

● When writing compound expressions, you should be explicit


and indicate with parentheses which operators should be
evaluated first.
EXPRESSIONS

● A block is a group of zero or more statements between balanced


braces.
● Statement blocks are commonly used with functions, decision
statements, iteration statements, class definitions etc.
● Eg.
if(condition){
/* statements */
}

You might also like