Thursday, 21 July 2016

MATLAB Programming 34 - nested switch case statement (Example)

Example


Create a script file and type the following code in it:


a = 100;

b = 200;

switch(a)

case 100

fprintf('This is part of outer switch %d\n', a );

switch(b)

case 200

fprintf('This is part of inner switch %d\n', a );

end

end

fprintf('Exact value of a is : %d\n', a );

fprintf('Exact value of b is : %d\n', b );

When you run the file, it displays:


This is part of outer switch 100

This is part of inner switch 100

Exact value of a is : 100

Exact value of b is : 200

No comments:

Post a Comment