Control statments

Proceeding further with Java programming basics now our target is java programming control statements .java has three type of Control statements
·         Sequence
·         Selection
·         Repetitions


Sequence Structure

It is most trivial Structure. In this type of control statement, there is a simple execution of the statement in the programmer sequence of code. The compiler just executes them the way they are written.

Example

 
Mathematical calculations 

Simply execution of statements in sequence.

Selection statement:

In selection statement, the program has given two paths dependent on two paths if condition one executes do this else do that. The compiler has to select according to the condition. There are three further types of selection statements. Most important thing is that if-else statements are used for selection statements.
·         If statement (if (condition) execute statement 1)

                                                                    Example





If the value of x is greater than 0 its shows the number is positive.
·         If-else (if(Condition) execute Statement 1, else execute statement 2)
                           
                                       Example



·         Switch (Switch(condition) which case is equal to condition compiler will execute its statement.

Ø  execute case 1 Statement break
Ø  execute case 2 Statement 2 break
Ø   execute case 3 statement 3 break …...
Ø  Default)
ü  Example:



Simple if statement is single selection, if-else double selection while a switch is multiple statements.

Repetition statement:

In the repetition statement, the program has to repeat itself until a certain condition is not achieved. There are three famous loops statements
  •         While loops (it is sentinel control until a specific condition is not full fill it will repeat itself).

  • Do-while (in spite of condition it executes once and then it checks for condition).

  •  For loop (it is counter control loop it executes itself until the specified times it’s executed.



Post a Comment

0 Comments