Programming Basics/Printable version


Programming Basics

The current, editable version of this book is available in Wikibooks, the open-content textbooks collection, at
https://en.wikibooks.org/wiki/Programming_Basics

Permission is granted to copy, distribute, and/or modify this document under the terms of the Creative Commons Attribution-ShareAlike 3.0 License.

Introduction

Concepts edit

  1. What is programming?
  2. What is an algorithm?
  3. What is coding?
  4. What is a programming language?
  5. What is a translator?


Variables

Variables are tools which are used to store data.

Programming languages often use types to distinguish different kinds of data stored in variables.

Data Type Description Example 1 Example 2 Example 3
Integer Any whole number. 1 300 48
Character A letter of the alphabet. a z y
String A collection of text Wikibooks Programming Basics Hello world!


Functions

Functions used to store code that is used multiple times throughout a program, especially bits of code that repeat throughout a program.

Functions often take input to make them more versatile. This input is called an argument.


Conditions

Conditions are used in programming to only do something in the event of something else. This is incredibly useful in a number of tasks.

For example, one might prevent divide by zero errors by check to make sure the devisor is not zero first, and then only dividing if the devisor is not zero.


Loops

Loops are used to repeat sections of code, either infinitely, or until a condition is met.

There are two common types of loops, While loops and For loops.


Arrays

Arrays are used to hold multiple related variables.

Example Array
0 1 2 3 4
A r r a y


Strings

 
Diagram showing a string structure.

A string is a data type used to store sequences of characters. Strings are often simply an array of characters.


Files

Files are used to save data to a storage device, which is useful for a number of purposes.



Objects

Objects are a useful tool to handle flexible situations in code. Object Oriented Programming style uses objects extensively.