2014-01-09 49 views
-1

我所见过的所有编程语言都有非常相似的条件语句和循环语句:if语句,switch语句在许多语言中共享(奇数Python没有switch语句)。循环使用相同:forin)和(dowhile循环用于许多种语言。是否有任何定义非标准控制流程语言的语言?

这让我想到:是否有任何语言定义其他条件语句或循环语句(基于新颖的想法,而不仅仅是更名为if)?

我可以想到三元运算符? :但我很好奇,如果有任何语言做条件/循环比标准的方式不同。

+0

[goto](http://en.wikipedia.org/wiki/Goto) – celeriko

+1

http://en.wikipedia.org/wiki/LOLCODE – bf2020

+0

“列出具有属性X的事物”的问题并不适合为这个网站。 –

回答

0

Python可能没有内置switch语句,但仍然可以模拟它。

switch = {1: func1, 2: func2, 3: func3} # case statements 
switch.get(switchvar, default)() # default is used if the cases are not matched 

下面是一些有趣的事情,你可以在C做++(偶尔确实有使用):

// default 
template <int i> void int_switch() 
{ 
    std::cout << i << '\n'; 
} 

// case 1 
template<> void int_switch<1>() 
{ 
    std::cout << "one\n"; 
} 

// case 2 
template<> void int_switch<2>() 
{ 
    std::cout << "two\n"; 
} 

const int switch_var = 3; 
int_switch<switch_var>(); // Outputs "3\n" 

当然,只有当模板参数是一个常量表达式,因此使用的作品const int而不是只有int