c/c++、c#、java、python、matlab 循环与分支比较

本文深入探讨了多种编程语言中的循环和判断结构,包括C/C++、C#、Java、Python和MATLAB的for循环、while循环、do...while循环、foreach循环以及if...else条件判断、switch...case选择结构,解析了各种控制语句如break和continue的使用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 c/c++c#java
循环

for(init;condition;increment){ }

while(condition){ }

do{ }while(condition);

break;  //跳出循环

continue; //跳过一次循环

for(init;condition;increment){ }

foreach(datatype variable in array){ }

while(condition){ }

do{ }while(condition);

break;  //跳出循环

continue; //跳过一次循环

for(init;condition;increment){ }

while(condition){ }

do{ }while(condition);

for(datatype variable : array){ }

break;  //跳出循环

continue; //跳过一次循环

 

判断

if(condition){ }

else{ }

switch(expression)

{

    case option :

        statements;

        break;       //可选,跳出判断

            \tiny \vdots

    case option :

        statements;

        break;        //可选

    default         //可选

        statements;

}

if(condition){ }

else{ }

switch(expression)

{

    case option :

        statements;

        break;       //可选,跳出判断

            \tiny \vdots

    case option :

        statements;

        break;        //可选

    default :         //可选

        statements;

}

if(condition){ }

else{ }

switch(expression)

{

    case option :

        statements;

        break;       //可选,跳出判断

            \tiny \vdots

    case option :

        statements;

        break;        //可选

    default :         //可选

        statements;

}

 pythonmatlab 
循环

while condition:

    statements

for variable in sequence

    statements

break;  //跳出循环

continue; //跳过一次循环

pass; //不做任何事情,一般用做占位语句,为了保持程序结构的完整性

while(condition)

    statements;

end

for index = array
   statements
end

for index = initval:endval  
   statements
end

for index = initval:step:endval  
   statements
end

break;  //跳出循环

continue; //跳过一次循环

 
判断
if condition:
    statements;
elif condition:
    statements;
elif condition: 
    statements;
else:
    statements;

if condition
   statements;

elseif condition

    statements;

elseif condition

    statements;

else

    statements;
end

switch expression

   case option

      statements

   case option

      statements

          \tiny \vdots

   otherwise

      statements

end

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值