多程式語言語法對照表
- 2019 年 11 月 20 日
- 筆記
背景
有時候會出現一天內使用多種語言進行開發的情況,比如在python, matlab, java, c++之間來回切換, 稍不注意就會把語法規則搞錯,影響效率。
本文致力於解決上述問題,主要提供了各語言語法層面的差異,如變數操作、邏輯跳轉等語句,供快速查詢。
python
- 條件跳轉
1234 |
if if_clause: process 1else: process 2 |
---|
- 循環
12345678910111213 |
# while 循環while while_clause: while_process# for 循環for i in iterable_object: for_process# break break # continue continue |
---|
- 關係運算
- 等於 ==
- 不等於 !=
- 大於 >
- 小於 <
- 邏輯操作
- 與 and
- 或 or
- 非 not
matlab
- 條件判斷 12345678910% if 之後不加括弧,不加冒號% <statements>不需要括弧if <expression> <statements>;else <statements>;end
- 循環
123456789101112131415161718 |
% while循環while <expression> <statements>;end% for 循環% 使用index = values來控制循環次數for index = values <program statements>;end% continuecontinue;% breakbreak; |
---|
- 關係運算
- 小於 <
- 大於 >
- 等於 ==
- 不等於 ~=
- 邏輯運算
- 與 &&
- 與 AND
- 或 ||
- 或 OR
- 非 NOT
JavaScript
- 條件語句
12345678 |
if (condition) { <statements>; } else { <statements>; } |
---|
- 循環 1234567891011121314151617181920212223// while 循環 while (condition) { statements; }// do while 循環do{ statements;}while (condition);// for 循環for (initial; condition; statements) { statements;}// breakbreak;// continuecontinue;
- switch語句 12345678910111213switch(condition){case statements: statements; break;case statements: statements; break;default: statements;}
- 關係運算
- 小於 <
- 大於 >
- 等於 ==
- 不等於 !=
- 邏輯運算
- 與 &&
- 或 ||