Maximum number of nested conditions allowed

Does anyone know the limits of the nested conditions (I mean the conditions in another, several times)? In, say, Java and Visual Basic.

I remember when I started with my evolving trace, I do, I think, 3 nested conditions in VB 6 and the compiler just didnโ€™t go into the third, now that I remember, I never knew what the maximum nested encodings that can take tongue.

+1
source share
6 answers

There is no restriction on the REAL programming language. For VB.NET and Java, I would be shocked if there is any limit. The limit will NOT be memory, because we are talking about COMPILE TIME constraints, not environment constraints.

This only works in C #: It should be noted that the compiler can optimize this so as not to even use IF.

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 too optimized:

 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(); } 
+4
source

I agree with most people here that there are no restrictions on writing if blocks. But the maximum size for the java method exists. I believe its 64K.

+2
source

If you mean nested if blocks, then there is no theoretical limit. The only limitation is the available disk space for storing source code and / or compiled code. There may also be a runtime limit if each block generates a new stack stack, but again this is just a memory limit.

The only explanation for your empirical result 3 is either a programming error or an error in interpreting the results.

+1
source

I have to agree that the limit is based solely on memory limitation. If you achieve this, I would expect you to reach a certain limit, however I doubt that it is likely that you will reach this limit.

I could not find the source of the backup link, but a quick test of 40+ nested if commands compiled and works fine.

0
source

The limit on the number of nested conventions will almost certainly be based on the size of the compiler stack and data structures and will have nothing to do with the runtime, except, possibly, in cases where the code space of the target environment is very limited compared to the memory available to the compiler (for example, using a modern PC to compile a program for a small microcontroller with 512 bytes of flash). Please note that no RAM (outside of any code used to store the code itself) is required at runtime to evaluate a deeply nested combination of logical operators other than what its most complex term (i.e., the memory needed to calculate " (foo () || bar ()) & boz () 'is the largest memory needed to evaluate foo (), bar () or boz ()).

In practical terms, it is impossible to reach the limit using a modern compiler on a modern machine, unless you wrote a โ€œprogramโ€ to exceed it (I would expect that the limit is likely to be from 1,000 to 1,000,000 breeding levels, but even if "only" 1000 there is no reason for nesting things that are deep).

0
source

Logically, I would think that the limit would be based on the memory available to the Java application.

-1
source

Source: https://habr.com/ru/post/891729/


All Articles