當前位置:編程學習大全網 - 編程軟體 - Matlab中如何使用if語句?

Matlab中如何使用if語句?

嵌套if語句的語法如下:

if <expression 1>

% Executes when the boolean expression 1 is true?

if <expression 2>

% Executes when the boolean expression 2 is true

end

end

例如:

創建腳本文件並在其中鍵入以下代碼 :

a = 100;

b = 200;

% check the boolean condition if( a == 100 )

% if condition is true then check the following?

if( b == 200 )

% if condition is true then print the following?

fprintf('Value of a is 100 and b is 200\n' );

end

end

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

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

執行上面示例代碼,得到以下結果:

Value of a is 100 and b is 200

Exact value of a is : 100

Exact value of b is : 200

擴展資料:

C語言提供了三種形式的if語句:

1、if(表達式)語句。

例如:

if(x>y)printf("%d",x);

2、if(表達式)語句1 else 語句2。

例如:

if(x>y)printf("%d",x);

else?printf("%d",y);

3、在每個語句中,可以有多個語句,但需要加上大括號。

例如:

if(x>y){printf("%d",x);break;}

百度百科—if語句

  • 上一篇:提供設計服務註冊商標屬於哪壹類?
  • 下一篇:完了bbq了是什麽意思梗?
  • copyright 2024編程學習大全網