A program is made up of sentences which are also called statements. In computer languages there are a few types of sentences. The following describes the grammar of some programming languages. The significant words and punctuation are highlighted in green.
- Data definition
- A data definition sentence starts with a data type word such as int followed by a list of variable names.
- expression
- An expression is variables, numbers and function calls joined with operators such as a = b + 5 and followed by a ;
- block
- A block starts with a { followed by some sentences and then a }
- if
- An if sentence starts with if followed by ( expression ) sentence the sentence can be followed by else sentence
- switch
- Switch allows serveral values to be tested. Makes it easier to read than a multiple if then else if then else type sequence.
- while
- A while sentence starts with the word while and is followed by ( expression ) sentence
- for
- for ( init ; test; next ) sentence
- return
- Return a value from a function.
- break
- In a while or for loop, exit the loop. In a switch statement, jump to the end.
- continue
- In a while or for loop, go back and start the loop again.