Comp 110 Statements

Statements

Every statement you write is a separate instruction you're giving the computer.

Statements usually they end with a semicolon (;). In stored programs, you can write a bunch of statements and, when the program runs, the computer evaluates each statement individually.

We explain what we want a program to do using statements. For example, statements are used every time we declare or initialize a variable, or when we assign a new value to a variable. We also use statements in other ways, such as when we print things.

Let's see an example:

let person: string; // variable declaration statement!
 
person = "Michael Scott"; // variable assignment statement!
 
let quote = "'I'm not superstitious, but I am a little stitious.'";
// in the above line, we are declaring and initializing a variable in one statement!
 
print(quote); // print statement
 
print("~ " + person); // print statement
 
/* The printed output of this program looks like this:
 
'I'm not superstitious, but I am a little stitious.'
~ Michael Scott
 
*/


To get a better idea of what's really happening in a statement, let's look at the first print statement from our example: print(quote);

In that statement, we're telling the computer to print to the screen the string that is stored in the quote variable. So, when we run the program the computer will find what's stored in the quote variable ("'I'm not superstitious, but I am a little stitious.'") and print that out on the screen. Next, since that's all we included in that statement the computer will move on to the next statement and then keep going until it has gone through all the statements in your program.