问题描述
有人知道嵌套条件的极限吗?假设是Java和Visual Basic.
Does anyone knows the limit of nested conditions (I mean conditions under another, several times)? In, let's say, Java and Visual Basic.
我记得当我开始进行开发跟踪时,我认为在VB 6中创建了3个嵌套条件,而编译器没有进入第三个条件,现在我记得我从未知道过嵌套的maximun语言可以接受的条件.
I remembered when I was beginning with my developing trace, I make, I think 3 nested conditions in VB 6, and the compiler, just didn't enter the third one, now that I remember I never, knew the maximun nested coditions a language can take.
推荐答案
对于REAL编程语言,应该没有限制.对于VB.NET和Java,如果有任何限制,我会感到震惊.限制将不是内存,因为我们在谈论的是COMPILE TIME约束,而不是环境约束.
No limit should exist for a REAL programming language. For VB.NET and Java I would be shocked if there is any limit. The limit would NOT be memory, because we are talking about COMPILE TIME constraints, not executing environment constraints.
这只能在C#中找到:应该注意的是,编译器可能会对此进行优化,甚至不使用IF.
This works just find in C#: It should be noted that the compiler might optimize this to not even use the IFs.
static void Main(string[] args)
{
if (true)
{
if (true)
{
if (true)
{
if (true)
{
if (true)
{
if (true)
{
if (true)
{
if (true)
{
if (true)
{
if (true)
{
if (true)
{
if (true)
{
if (true)
{
if (true)
{ Console.WriteLine("It works"); }
}
}
}
}
}
}
}
}
}
}
}
}
}
}
不应对此进行过多优化:
This should not be optimized too much:
static void Main(string[] args)
{
if (DateTime.Now.Month == 1)
{
if (DateTime.Now.Year == 2011)
{
if (DateTime.Now.Month == 1)
{
if (DateTime.Now.Year == 2011)
{
if (DateTime.Now.Month == 1)
{
if (DateTime.Now.Year == 2011)
{
if (DateTime.Now.Month == 1)
{
if (DateTime.Now.Year == 2011)
{
if (DateTime.Now.Month == 1)
{
if (DateTime.Now.Year == 2011)
{
if (DateTime.Now.Month == 1)
{
if (DateTime.Now.Year == 2011)
{
if (DateTime.Now.Month == 1)
{
if (DateTime.Now.Year == 2011)
{ Console.WriteLine("It works"); }
}
}
}
}
}
}
}
}
}
}
}
}
}
Console.ReadKey();
}
这篇关于允许的最大嵌套条件数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!