Jumping statement:-

The Jumping Statement can be defined as which guides the program counter to jump from one statement to another statement.
The division of the jumping statement can be understandable through the digram:-


Note:-
program counter:- it is a special type of pointer used to store the address of next to be executed.

According to the execution of the program, it can be of 2 types.
  • Procedural Programming:- The method of solving a problem in a step by step method is known as Procedural Programming.
  • Modular Programming:- The method of dividing the whole program into some sets of subprograms method is known as Procedural Programming.
Note:- 
MATLAB is an example of both procedural and modular programming language. However, it also can be used as an object-oriented language.

Loops:-

Loops can be defined as the block of statement which executes is self again and again until a condition become false.

We can not control the execution of the block of statement discreetly i.e. once it started execution it can not be stopped or controlled as per the desire of the programmer.
(Algorithm of Loop Statement)
In MATLAB, we are learning 2 types of loops. Such as:-
  1. For Loop
  2. While Loop

1.For Loop:-

For Loop is an entry checking Loop, i.e. it checks the program at the initialisation point whether it is true or false. 
For loop can be initialized in 3 types:-

A.initial: end:-
This for loop is used only when the initial between two index is 1 this is going repetitive execution until the end is greater than the index

Syntax:-

for <intial: end>
           ...............................
    end

B. initial: step: end:-
This for loop is used only when the interval between two index can be modified as per programmers desire. 

Syntax:-

for <initialisation: step or difference: ending point>
    ...........
    ...........
    ...........
end

C. valArray:-
This for loop is used when we want to create an array or for exact to create a column array or column vector index.

Syntax:-

for [index = val1,val2,val3]
    ...........
    ...........
    ...........
end

2.While Loop:-

  • It executes a block of statement again and again if it is true.
  • it checks the condition before it executes the statements.

Syntax:-

initialisation;
while(condition)
    ...........
    ...........
    any change in condition variable;
end

Loop Controlling Statement:- 

The loop controlling statement can be defined as the specialized programmed statements which actually control the execution of the statements in the loops.

In MATLAB, there are 2 types of Loop Controlling statements. such as:-
  1. Continue
  2. Break

1. Continue:-

The continue Statement drives the program counter to any change in variable state, where it can start execution of the loop again and again.

For example:-

  1. clc;
  2. clear all;
  3. close all;
  4. i=16;
  5. while(i<=36)
  6.     if(i==5)
  7.         continue;
  8.     end
  9.     i=i+2;
  10.     fprintf(' %d ',i);
  11. end
 ans:
     18  20  22  24  26  28  30  32  34  36  38 >> 

2.Break:-

The break Statement drives the program counter out of the loop, where it can stop execution of the loop again and again.

For example:-

  1. clc;
  2. clear all;
  3. close all;
  4. i=0;
  5. while(i<=10)
  6.     if(i==5)
  7.         break;
  8.     end
  9.     i=i+1;
  10.     fprintf('%d',i);
  11. end
ans:
     1  2  3  4  5 >> 
contact-form

Post a Comment

If you have any doubts regarding this topic...
feel free to ask...

Previous Post Next Post