Typically, when someone refers to a nested loop, I think of a loop inside a loop. Same for a nested if statement - an if inside an if.

But does it have to refer to that? I mean, would you consider a loop inside an if statement a nested loop? Or an if inside a loop a nested if?

Basically, to be a nested x, does the thing that it is nested inside of have to be another x?

Note: Hopefully obvious, but I'm not asking if it's possible to do these things. Of course it's possible. I'm asking about terminology - "would it make sense to refer to these things this way", not "is it possible to do this thing I'm describing".

有帮助吗?

解决方案

Yes, I would say that for a loop to be called nested that it is inside of another loop. This distinction may seem trivial in everyday discussion, but when it comes to analyzing the Big-O runtime of code it makes a huge difference for a "nested" loop to actually be inside of another loop and not an if block.

其他提示

You would refer to loops nested in if statements or vice versa as nested code blocks or nested statements.

Nested loops must be nested in other loops and nested if statements must be nested in other if statements.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top