Sunday, 21 August 2016
Statements and Expressions
When reading a book or story you extract meaning from an ordered chain of words.
In a similar way, computers extract commands from a chain of ordered instructions.
In English we call this a sentence; programmers call this a statement.
A statement is considered to be any chunk of code which accomplishes some sort of task separated by a semicolon. At the center of any given task is the algorithm, not to be confused with a logarithm.
An algorithm is a systematic process that accomplishes something. In many ways you can think of it as a recipe, or rather a recipe is an algorithm for making food.
It can take just one or two statements to accomplish a task, or it could take many hundreds of statements.
This all depends on the difficulty of a given task. Each individual statement is a step toward a goal. This is the difference between spending a few minutes frying an egg, or spending an hour baking a souffle. Each step is usually fairly simple; it’s the final result that matters.
Like sentences, statements have different forms. Statements can declare and assign values to variables. These are called declaration and assignment statements. These statements are used to set up various types of data and give them names.
Expressions The subjects of your statements are called identifiers. An assignment statement is used to give an identifier a value. When you read “Jack is a boy and Jill is a girl,” you’ve mentally assigned two subjects their genders. In C# this might look more like:
gender Jack = male; gender Jill = female;
Assignment statements often incorporate some sort of operation.
These are called expressive statements. Different from expressing an emotion, expressions in code look more like “x + y.” Expressions process data. After processing, the result of an expression can be assigned to a variable.
A collection of statements is called a code block, not like a roadblock which might stop your code, but more like a building block, anything that’s used to build.
When writing a story, we call a collection of sentences a paragraph. The statements in a block of code work with each other to accomplish a task.
In a similar way, computers extract commands from a chain of ordered instructions.
In English we call this a sentence; programmers call this a statement.
A statement is considered to be any chunk of code which accomplishes some sort of task separated by a semicolon. At the center of any given task is the algorithm, not to be confused with a logarithm.
An algorithm is a systematic process that accomplishes something. In many ways you can think of it as a recipe, or rather a recipe is an algorithm for making food.
It can take just one or two statements to accomplish a task, or it could take many hundreds of statements.
This all depends on the difficulty of a given task. Each individual statement is a step toward a goal. This is the difference between spending a few minutes frying an egg, or spending an hour baking a souffle. Each step is usually fairly simple; it’s the final result that matters.
Like sentences, statements have different forms. Statements can declare and assign values to variables. These are called declaration and assignment statements. These statements are used to set up various types of data and give them names.
Expressions The subjects of your statements are called identifiers. An assignment statement is used to give an identifier a value. When you read “Jack is a boy and Jill is a girl,” you’ve mentally assigned two subjects their genders. In C# this might look more like:
gender Jack = male; gender Jill = female;
Assignment statements often incorporate some sort of operation.
These are called expressive statements. Different from expressing an emotion, expressions in code look more like “x + y.” Expressions process data. After processing, the result of an expression can be assigned to a variable.
A collection of statements is called a code block, not like a roadblock which might stop your code, but more like a building block, anything that’s used to build.
When writing a story, we call a collection of sentences a paragraph. The statements in a block of code work with each other to accomplish a task.
Subscribe to:
Post Comments
(
Atom
)

No comments :
Post a Comment