And here we have it we are in my most interesting topic in programming which is control statements. My definition of control statement is that it is the brain of the program in that it contains the decision making mechanism of a program. Control statements or control structures can be grouped into 3 major parts
-
Sequence - This is the mechanism carried out by the compiler and the system itself and it is a type of mechanism that defines that a program follows a sequence of execution based majorly on the sequence in which the code is written. It is basically what comes first get executed first
-
Selection - This is the decision making mechanism of the program. And the different selection control statements we have are:
- if statement
- if-else statments
- switch statements
There usage is shown below: if statement if(5>0) System.out.print("Five is greater than 0");
if-else statement if(5<0) System.out.print("Five is less than 0") else System.out.print("Five is greater than 0") Switch is best shown in a real program but what it basically does is that it takes a value and checks for the different cases of the value. Like it can take a number and check if it is 5, 4, 3, using switch and case and provides for what should happen if the value is any of the values in the different cases.
Pseudocode is a false code from its name pseudo-false and code, and it is basically a way of simplifying the code that is to be written in more human readable language. It helps to define the flow of the program and what should be done at any point. Note: pseudocode is not compiler-readable(a compiler is what converts your code to machine code, a java compiler converts its code to bytecode which is platform independent, which makes java a write once, run anywhere)
Algorithm is the order and action that you specify your program to carry out. A very good algorithm follows a very good order and performs an action in the most optimal way. Algorithm is like the routine your program passes through to do what it is supposed to do. In getting the algorithm for your program do well to not follow the wrong other like using an object to a variable before creating the object because this will cause a logical error in your code.
Operators and Structured programming will be discussed in our tutorial sessions