Follow Us :
Course Content
Introduction
What is a Code? How Coding works What is Programming and how it works Coding and Programming Ethical practice in coding
0/2
Basic Coding Concepts
1. Variables 2. Data Structures 3. Control Structures 4. Syntax 5. Tools
0/2
Introduction to Coding
About Lesson

 The 5 Basic Coding Concepts

Here are five of the most important coding concepts that every young learner should know:

1.Variables

2.Data Structures

3.Control Structures

4.Syntax

5.Tools

2.1 Variables

As the foundation of any computer programming language, variables act as “containers” that “hold” information. These containers then store this information for later use.

For example, imagine you are visiting the homepage of a website. Once you land on this page, a dialog box pops into view with this simple greeting: “Hi! What’s your name?” This dialog box is a variable! In this code, the programmer could name this variable “visitorName.” This means that when you type your name into the form and hit submit, your information would be stored in the “visitorName” variable. The programmer could then reference this variable at any time to access the information it contains.

2.1 Variables

For example, the variable ‘a’ could contain the number 5 and the variable ‘b’ could contain the number 10. During execution of the program, the statement “a + b” is replaced by the Actual Values “5 + 10” and the result becomes 15.

2.1.1 Variable Declaration

In coding, variables are declared by giving it a name and setting it to a value using an equal sign (‘=’). Variables can later be reassigned to other values.

Example, myName = ‘Temi’

2.1.2 Data Type Definition

In coding, data types are how computers classify different forms of information. They include

  • numeric,
  • string and
  • boolean types.

2.1.2.1 Numbers Definition

In programming, numbers are a common data type. They represent numerical values and can include numbers with and without decimal points. Examples -25, 0, 0.484850, 19203

2.1.2.2 String Definition

In programming, strings are a common data type. They are any sequence of characters (letters, spaces, numbers, or symbols) surrounded by single or double quotes. Strings are commonly used to represent text, speech, symbols, and other non-numerical characters.

Example,

“Hello World”

“Great Work!”

2.1.2.3 Boolean Definition

In programming, booleans are a common data type. They represent the logical ideas of true and false.

AND Operator

In programming, the logical AND operator (&&) compares two values. It returns true when both values evaluate to true and false otherwise.

The following evaluates to true: grass is green AND fire is red 2 > 1 AND 6 > 5 3 == 3 AND 8 == 8

While this evaluates to false: trees are large AND ant are massive 5 < 4 AND 6 > 3 7 == 7 AND 0 == 9

2.2 Data Structures

Data structures allow programmers to streamline data collection when a large amount of related information is involved. Let’s go back to our “visitorName” variable from above, but imagine the computer programmer needs to store and reference 10 different visitors’ names rather than just one.

Rather than creating 10 different variables for each new visitor — which would increase the sheer amount of text in the program and make adding or removing new contacts difficult — the programmer could simply use a data structure to contain all related variables. In this case, the data structure would be a List.

With this List data structure, the programmer only needs to create one variable rather than 10, which means the code would be much more flexible to change.

2.2.1 List Definition

In programming, lists are a basic data structure that stores multiple pieces of information in an ordered, linear sequence.

myList = [“apples, “grapes”, “banana”]

2.2.2 List Index Definition

In programming, the position of a value in a list is known as its index. An item in a list can be accessed by its index.

myList = [“apples, “grapes”, “banana”]

myList [1] // return ‘banana’, if list is zero

2.2.3 List Append Definition

In programming, when item is added to the end of a list, this is known as appending.

myList = [“apples, “grapes”, “bananas”]

myList.append(“pears) // adding an item to the list

// returns myList = [“apples, “grapes”, “banana”, “pears”]

2.3 Control Structures

A control structure analyzes variables and selects a direction in which to go is determined from the given parameters. For example, when a computer program is running, the code is being read by the computer line by line from top to bottom and (for the most part) left to right.

As the code is being read, the computer will reach a point where it needs to make a “decision” (based on strict rules set by the computer programmer). At this point, the code could do things like jump to a different part of the program, re-run a certain piece of code again, or simply skip a block of code altogether.

Whatever parameters are set by the programmer will affect the code flow. Think of control structures as the directions your program needs to allow it to make choices and execute commands under different conditions.

2.3.1 Control Structures

The three basic control structures in virtually every procedural language are:

1.Sequence

2.Conditional

3.Iterative

2.3.1.1 Sequence

Sequence is the default control structure; instructions are executed one after another.

Example: ax2 + bx + c = 0.

2.3.1.2 Conditional

The conditional IF-THEN or IF-THEN-ELSE control structure allows a program to follow alternative paths of execution.

The simplest form of IF statement associates a condition with a sequence of statements enclosed by the keywords THEN and END IF (not ENDIF), as follows:

IF condition THEN sequence_of_statements; END IF;

The sequence of statements is executed only if the condition yields TRUE. If the condition yields FALSE or NULL, the IF statement does nothing. In either case, control passes to the next statement. An example follows:

IF sales > quota THEN compute_bonus(empid); UPDATE payroll SET pay = pay + bonus WHERE empno = emp_id; END IF;

2.3.1.3 Iterative

Iteration, or looping, gives computers much of their power. They can repeat a sequence of steps as often as necessary, and appropriate repetitions of quite simple steps can solve complex problems.

2.4 Syntax

Just like in the English language, computer programming follows a syntax or a set of rules that define particular layouts of letters and symbols. Proper syntax ensures the computer reads and interprets code accurately. For example, let’s consider a simple email address and its required syntax.

Email addresses are understood by readers and computers immediately due to their format. Typically, email addresses must consist of a string of letters and numbers, followed by the “@” symbol, and finally a website domain (e.g., bob_smith@companyname.com). This structure is known as the standard email syntax! It’s easy to imagine that if the email address were not syntactically correct (company@.comnamebob_smith), computers would not be able to process it.

In a similar fashion, each computer programming language has its own syntax or appropriate order in how code should be written for the program to understand what it is supposed to do.

2.4.1 Levels of Syntax

To simplify understanding and analyzing a language’s syntax, we separate syntax into three levels:

1.Words – the lexical level, determining how characters form tokens;

2.Phrases – the grammar level, narrowly speaking, determining how tokens form phrases;

3.Context – determining what objects or variables names refer to, if types are valid, etc.

2.5 Tools

In the physical world, tools allow workers to perform tasks that would otherwise be extremely difficult (think of how a hammer helps drive a nail into a piece of wood and what this job would be like without tools). Similarly, a tool in computer programming is a piece of software that helps programmers write code much faster.

For example, one of the most important tools for computer programmers is an Integrated Development Environment (IDE). An IDE can check the syntax of code for errors, organize files, autocomplete commonly used code, and help you easily navigate through your code. Tools are the final crucial element to code, as they streamline processes and ensure accuracy.

Coding uses traditional code/program editing tools like notepad, notpad++, and so on.

Windows Notepad is a simple text editor for Windows; it creates and edits plain text documents. First released in 1983 to commercialize the computer mouse in MS-DOS, Notepad has been part of every version of Windows ever since.

Notepad++ is a free source code editor and Notepad replacement that supports several languages.

Exercise Files
Introduction to Coding.pdf
Size: 1.51 MB