Programming Methods II

Chapter 2 

Variables

Control Structures and Calculations 

Objectives

  • Understand what variables are 
  • Identify what data types are and how to use them with variables 
  • Describe the naming conventions for variables 
  • Identify and use arithmetic operators 
  • Understand the importance of the order of precedence 
  • Describe control structure 

Variables 

A variable is a placeholder for values in memory. A variable is a space in memory where data is stored 

Bitcoin is rising to buy some, click here...

Data Types 

You must decide what to put into variables i.e. a bowl designated for serving humans would not be used for serving animals. Data types tell the computer what kind of data the variable would contain. This makes it possible for the computer to reserve the relevant space for the variable

Data Types 


  • Integer(int): Positive and negative whole numbers e.g. 20,4,-23, etc. . 
  • Float/real : Positive and negative rational (fractional) numbers e.g. 20.03,4.01,-23.00, etc. .
  • Double: Like float but reserves more memory.
  • Character(char) : single letters, numbers and special characters e.g. a,Y,7,etc. .
  • String: A collection(array) of characters such as names e.g. Roland, church, etc.
  • Boolean(bool): True or false(1,0) 

Bitcoin is rising to buy some, click here...

Naming Variables Rules

  1. Should not start with a number i.e. 3age etc. but can have numbers within the name or at the end of the name. 
  2. Should not contain a dot(.) i.e. first. name etc. 
  3. Should not contain spaces i.e. first name etc. 
  4. Should not contain special characters i.e. first#name, first~name, etc. . except underscore(_) 

Naming Variables 

  • Variable names should  express what they would store 
  • Be simple and straightforward 
  • Be written together as one word if the name spans more than one word e.g. first name. 
  • Be written by capitalizing the first letter of each word e.g. FirstName(Camel Casing). 

Arithmetic Operators

  •  + means add
  • - means subtract 
  • * means multiply 
  • / means divide 
  • % means modulo Arithmetic Operators 

Order of precedence (BODMAS / BEDMAS)



  • Brackets 
  • Exponents 
  • Multiplication 
  • Division 
  • Addition 
  • Subtraction 

Assignment Operator 

Equals to(=): The assignment operator is the = symbol. It is used to give the value of what is to its right to what is on the left for example int a; a=10

NB: The reverse is not true 

Control Structure 

A syntactic form in a language to express the flow of control. 

TYPES 

  1. Sequence.
  2. Selection. 
  3. Loop.

Earn free bitcoins here...

Comments

Popular posts from this blog

Top 5 Programming Languages to Land you a Job

Programming Methods 1

Avoiding HDD(Hard Disk Drive) crash