switch(ch1)
case'A'
fprintf('This A is part of outer switch');
switch(ch2)
case'A'
fprintf('This A is part of inner switch' );
case'B'
fprintf('This B is part of inner switch' );
endcase'B'
fprintf('This B is part of outer switch' );
end
在线示例
创建一个脚本文件并在其中键入以下代码-
a = 100;
b = 200;
switch(a)
case100
fprintf('Thisis part of outer switch %d\n', a );
switch(b)
case200
fprintf('Thisis 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 );
运行文件时,它显示-
This is part of outer switch100
This is part of inner switch100
Exact value of a is : 100
Exact value of b is : 200