Codecademy Logo

Intro to Blockly

Loop Definition

In programming, a loop is a programming structure that repeats a set of instructions until a specified condition is met. Loops are commonly used in programming because, compared to repeated lines of code, they save time, reduce error, and are easy to read.

A loop to play a sound may look like this:

UNTIL 4 sounds have been played:
    Play a sound

For Loop Definition

In programming, a for loop executes a set of instructions for a specified number of times.

A for loop to add landmarks to a map may look like this:

UNTIL 20 landmarks have been added to the map:
    Add landmark to map

For Each Loop Definition

In programming, a for each loop executes a set of instructions for each item in a given collection.

A for each loop to add a list of destinations to a tourism application may look like this:

FOR EACH destination in the list:
    Add destination to app

While Loop Definition

In programming, a while loop executes a block of code as long as a given condition evaluates to true.

A while loop to make sandwhichs as long as there is bread left may look like this:

WHILE there is bread left:
    Make a sandwich

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

Variable Declaration

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

dogBreed = 'corgi'

Variable Definition

In programming, variables are used to assign a name to a piece of data and to use that name to reference the data elsewhere in the program.

myName = 'Zoe'

Data Structure Definition

In programming, data structures are an organized way to access and manage data.

List Definition

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

myList = ["apple", "banana", "grapes"]

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 = ["apple", "banana", "grapes"]
myList[1] //returns ‘banana’, if a list is zero-indexed

List Append Definition

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

myList = ["apple", "banana", "grapes"]
myList.append("pear") // adding an item to the end of a list in javascript
// returns ["apple", "banana", "grapes", "pear"]

Data Type Definition

In programming, data types are how computers classify different forms of information. They include numeric, string and boolean types.

For example, if using number data type, the program will know that arithmetic can be performed on it, but it can’t be capitalized.

Booleans Definition

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

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.

"Hello world"
"Great work!"

Numbers definition

In programming, numbers are a common data type. They represent numerical values and can include numbers with and without decimal points.

-25
0
.68888
7039

Define Function Definition

A function is defined by specifying its instructions, inputs, and name.

For example, a sandwich-making function takes in two inputs representing two ingredients. The definition in psuedocode would look like:

function makeSandwich(topping1, topping2) {
  Add bread
  Add topping1
  Add topping2
  Add bread
}

The name is makeSandwich, the inputs are topping1 and topping2, and the instructions are the four lines each starting with Add.

Function Inputs Definitions

“In programming, inputs to functions are known as parameters when a function is declared or defined. Parameters are variables that can be used inside the function body. When the function is called, these parameters will have the value of whatever is passed in as arguments.

For example, a sandwich-making function has two parameters:

function makeSandwich(topping1, topping2) {
  Add bread
  Add topping1
  Add topping2
  Add bread
}

We make a ham-and-cheese sandwich with makeSandwich("ham", "cheese"). We call the function with the arguments "ham" and "cheese". Those will be the values for the topping1 and topping2 parameters.”

Learn More on Codecademy