473,416 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

What do you call nested If...Then search loops?

GY2
I writing some documentation and I want to describe a common code structure
which is used to step through all the items in a collection (e.g. each file
in a subdirectory) while applying more and more restrictive filters so that
only the desired items can fall all the way through. This method is so
obvious and common it must have a name. What is it or at least, what is the
best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next

Nov 8 '06 #1
25 2175
Ugly? :-)

I would guess it would be called "Short Circuit Evaluation via Nested
If Then blocks"

Thanks,

Seth Rowe
GY2 wrote:
I writing some documentation and I want to describe a common code structure
which is used to step through all the items in a collection (e.g. each file
in a subdirectory) while applying more and more restrictive filters so that
only the desired items can fall all the way through. This method is so
obvious and common it must have a name. What is it or at least, what is the
best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next
Nov 8 '06 #2
GY2 wrote:
I writing some documentation and I want to describe a common code structure
which is used to step through all the items in a collection (e.g. each file
in a subdirectory) while applying more and more restrictive filters so that
only the desired items can fall all the way through. This method is so
obvious and common it must have a name. What is it or at least, what is the
best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next
>This method is so obvious and common it must have a name. What is it or at least, what
is the best (short) way to describe it?
It is usually called a (SELECT) CASE structure. For those who do not
use CASE, it is called "Nested-IFs", and also "Bad Programming".

B.

Nov 8 '06 #3
GY2
Thanks for the 'Nested-Ifs' language.

"Brian Tkatch" <Ma***********@ThePentagon.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
GY2 wrote:
>I writing some documentation and I want to describe a common code
structure
which is used to step through all the items in a collection (e.g. each
file
in a subdirectory) while applying more and more restrictive filters so
that
only the desired items can fall all the way through. This method is so
obvious and common it must have a name. What is it or at least, what is
the
best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next
>>This method is so obvious and common it must have a name. What is it or
at least, what
is the best (short) way to describe it?

It is usually called a (SELECT) CASE structure. For those who do not
use CASE, it is called "Nested-IFs", and also "Bad Programming".

B.

Nov 8 '06 #4
GY2
Thanks. I like the 'short circuit evaluation' languague.

And btw, it often times doesn't look ugly at all, in fact the indented
structure makes it quite easy to grasp and to explain. It also doesn't run
too ugly either if the successive tests are ordered correctly. In fact it
can be pretty efficient because it minimizes the number of tests needed to
filter down to whatever one is seeking.

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Ugly? :-)

I would guess it would be called "Short Circuit Evaluation via Nested
If Then blocks"

Thanks,

Seth Rowe
GY2 wrote:
>I writing some documentation and I want to describe a common code
structure
which is used to step through all the items in a collection (e.g. each
file
in a subdirectory) while applying more and more restrictive filters so
that
only the desired items can fall all the way through. This method is so
obvious and common it must have a name. What is it or at least, what is
the
best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next

Nov 8 '06 #5
The other two posters who replied are being hyper-critical. There is a place
for nested if's. And, contrary to what one of them said, 'Select Case' is
not a general purpose replacement for nested if's.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"GY2" wrote:
I writing some documentation and I want to describe a common code structure
which is used to step through all the items in a collection (e.g. each file
in a subdirectory) while applying more and more restrictive filters so that
only the desired items can fall all the way through. This method is so
obvious and common it must have a name. What is it or at least, what is the
best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next

Nov 8 '06 #6
GY2
Thanks for the support, David. Yes, obviously Case statments would not work
for the multi-layered filtering I'm trying to document, but not receiving
perfect replies is no reason not to ask the question. It's good to be able
to receive something sent with a sense of humor in the same way. I thought
the one word reply--Ugly--was pretty funny.

"David Anton" <Da********@discussions.microsoft.comwrote in message
news:90**********************************@microsof t.com...
The other two posters who replied are being hyper-critical. There is a
place
for nested if's. And, contrary to what one of them said, 'Select Case' is
not a general purpose replacement for nested if's.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"GY2" wrote:
>I writing some documentation and I want to describe a common code
structure
which is used to step through all the items in a collection (e.g. each
file
in a subdirectory) while applying more and more restrictive filters so
that
only the desired items can fall all the way through. This method is so
obvious and common it must have a name. What is it or at least, what is
the
best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next


Nov 8 '06 #7
In the interest of not confusing GY2 even more... it is never called a
(SELECT) CASE structure. :-) All the tests need to be performed to
determine if [Found it] is reached. I'm not sure there is any term for this
except NESTED IF's. You could write it as a compound IF statement as well.

If [test 1] AndAlso [test 2] AndAlso [test 3] Then
[Found it]
End If

What matters most is what your tests consist of. If there are one or two
simple tests the compound form works fine. If there are a few more or they
are a bit more complicated then the nested format works. But if the tests
get "crazy" move all the comparison code into a method with a name that
identifies the set of tests like IsValidCustomer() and call that method from
within your For Each loop. Any overhead incurred by a method call is
outweighed by the advantage of skipping over the details when reading the
code and that the darn tests now have a name.

Oh and (when possible) place the most restrictive (i.e. unlikely to pass)
tests first. If earlier tests fail others don't have to execute.
"Brian Tkatch" <Ma***********@ThePentagon.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
GY2 wrote:
>I writing some documentation and I want to describe a common code
structure
which is used to step through all the items in a collection (e.g. each
file
in a subdirectory) while applying more and more restrictive filters so
that
only the desired items can fall all the way through. This method is so
obvious and common it must have a name. What is it or at least, what is
the
best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next
>>This method is so obvious and common it must have a name. What is it or
at least, what
is the best (short) way to describe it?

It is usually called a (SELECT) CASE structure. For those who do not
use CASE, it is called "Nested-IFs", and also "Bad Programming".

B.

Nov 8 '06 #8
David Anton wrote:
The other two posters who replied are being hyper-critical.
Actually, i answered the question. I also added a comment, because it
cannot be stressed enough. In most cases of nested-ifs, a CASE
statement should be used.
There is a place for nested if's.
It is rare. Besides, there are limits on how nested an IF can be. And,
it is *very* hard to follow in real code.
And, contrary to what one of them said, 'Select Case' is not a general purpose replacement for nested if's.
Yes it is. It also makes the code more clear. It is a rare case where
CASE cannot be used.

---

It could be that i'm so senstivie about this right now becaise i'm
fixing someone's code who indeed used nested IFs where CASE would
clearly be the choice. And since there are no comments, it makes
understanding the code twice as hard.

B.

Nov 8 '06 #9
We'll have to agree to disagree then. I find 'Select Case' more appropriate
where you care about many possible values of an expression.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"Brian Tkatch" wrote:
David Anton wrote:
The other two posters who replied are being hyper-critical.

Actually, i answered the question. I also added a comment, because it
cannot be stressed enough. In most cases of nested-ifs, a CASE
statement should be used.
There is a place for nested if's.

It is rare. Besides, there are limits on how nested an IF can be. And,
it is *very* hard to follow in real code.
And, contrary to what one of them said, 'Select Case' is not a general purpose replacement for nested if's.

Yes it is. It also makes the code more clear. It is a rare case where
CASE cannot be used.

---

It could be that i'm so senstivie about this right now becaise i'm
fixing someone's code who indeed used nested IFs where CASE would
clearly be the choice. And since there are no comments, it makes
understanding the code twice as hard.

B.

Nov 8 '06 #10
GY2
Thanks, Tom, but actually I'm not confused at all. I've been writing code
for 35 years and understand the concepts involved and now it looks as though
I may have answered my own question reasonably well in my original Subject
line. I really just wondered if this type of very common, practical, and
useful algorithm had a name these days.

Of course you're exactly right that a Select Case structure is completely
inadequate for this situation in which >ALL< tests need to be performed in
order to run all the filters.

And you also see that, of course, the way to make this most efficient is to
start with the most restrictive tests and step into the successively less
restrictive filters with each deeper nested If-Then.

"Tom Leylan" <ge*@iamtiredofspam.comwrote in message
news:uM**************@TK2MSFTNGP04.phx.gbl...
In the interest of not confusing GY2 even more... it is never called a
(SELECT) CASE structure. :-) All the tests need to be performed to
determine if [Found it] is reached. I'm not sure there is any term for
this except NESTED IF's. You could write it as a compound IF statement as
well.

If [test 1] AndAlso [test 2] AndAlso [test 3] Then
[Found it]
End If

What matters most is what your tests consist of. If there are one or two
simple tests the compound form works fine. If there are a few more or
they are a bit more complicated then the nested format works. But if the
tests get "crazy" move all the comparison code into a method with a name
that identifies the set of tests like IsValidCustomer() and call that
method from within your For Each loop. Any overhead incurred by a method
call is outweighed by the advantage of skipping over the details when
reading the code and that the darn tests now have a name.

Oh and (when possible) place the most restrictive (i.e. unlikely to pass)
tests first. If earlier tests fail others don't have to execute.
"Brian Tkatch" <Ma***********@ThePentagon.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
>GY2 wrote:
>>I writing some documentation and I want to describe a common code
structure
which is used to step through all the items in a collection (e.g. each
file
in a subdirectory) while applying more and more restrictive filters so
that
only the desired items can fall all the way through. This method is so
obvious and common it must have a name. What is it or at least, what is
the
best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next
>>>This method is so obvious and common it must have a name. What is it or
at least, what
is the best (short) way to describe it?

It is usually called a (SELECT) CASE structure. For those who do not
use CASE, it is called "Nested-IFs", and also "Bad Programming".

B.


Nov 8 '06 #11
The other two posters who replied are being hyper-critical.

Hey be nice! (joking) I did answer the post and put why nested if's are
important (short circuit evaluation).

The reason I put "Ugly" was more to emphasize how nested if's can
easily become giant scary beasts if used incorrectely. In it's pure
form (like in the example) this structure is very easy to read and
maintain. A lot of times programmers (new ones especially) will add way
to much stuff to the if then tests - like multiple exit points, etc. -
and cause the structure to become confusing and unmaintainable. I'm
sure with your experience you know what I'm talking about :-)
Now-a-days you could even replace the pure if-then structures with just
AndAlso statements if you wanted to.

Am I making more sense now?

Thanks,

Seth Rowe
David Anton wrote:
The other two posters who replied are being hyper-critical. There is a place
for nested if's. And, contrary to what one of them said, 'Select Case' is
not a general purpose replacement for nested if's.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"GY2" wrote:
I writing some documentation and I want to describe a common code structure
which is used to step through all the items in a collection (e.g. each file
in a subdirectory) while applying more and more restrictive filters so that
only the desired items can fall all the way through. This method is so
obvious and common it must have a name. What is it or at least, what is the
best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next


Nov 8 '06 #12
GY2
Sure you're making sense now, as you have all along--it's all good. I'm
working with old VB 6 code that's already a done deal. All I wanted to know
was what the hell to call those kinds of structures.

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
>The other two posters who replied are being hyper-critical.

Hey be nice! (joking) I did answer the post and put why nested if's are
important (short circuit evaluation).

The reason I put "Ugly" was more to emphasize how nested if's can
easily become giant scary beasts if used incorrectely. In it's pure
form (like in the example) this structure is very easy to read and
maintain. A lot of times programmers (new ones especially) will add way
to much stuff to the if then tests - like multiple exit points, etc. -
and cause the structure to become confusing and unmaintainable. I'm
sure with your experience you know what I'm talking about :-)
Now-a-days you could even replace the pure if-then structures with just
AndAlso statements if you wanted to.

Am I making more sense now?

Thanks,

Seth Rowe
David Anton wrote:
>The other two posters who replied are being hyper-critical. There is a
place
for nested if's. And, contrary to what one of them said, 'Select Case'
is
not a general purpose replacement for nested if's.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"GY2" wrote:
I writing some documentation and I want to describe a common code
structure
which is used to step through all the items in a collection (e.g. each
file
in a subdirectory) while applying more and more restrictive filters so
that
only the desired items can fall all the way through. This method is so
obvious and common it must have a name. What is it or at least, what is
the
best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next


Nov 8 '06 #13
GY2,

I always call it a nested If's inside a loop. As simple as you wrote it.

By the way about the comments, I assume that this is the most simple sample.
In any case nobody would use it like your sample of course.

You see that this is very well documentative when you see how ugly this is
mosly in all from C derived languages.

Cor

"GY2" <2m*******@wherever.comschreef in bericht
news:%2****************@TK2MSFTNGP03.phx.gbl...
>I writing some documentation and I want to describe a common code structure
which is used to step through all the items in a collection (e.g. each file
in a subdirectory) while applying more and more restrictive filters so that
only the desired items can fall all the way through. This method is so
obvious and common it must have a name. What is it or at least, what is the
best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next

Nov 8 '06 #14
GY2
Thanks Cor. Yes, the format in VB can be pretty nice if you're into
'literate programming'.

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:ud**************@TK2MSFTNGP02.phx.gbl...
GY2,

I always call it a nested If's inside a loop. As simple as you wrote it.

By the way about the comments, I assume that this is the most simple
sample.
In any case nobody would use it like your sample of course.

You see that this is very well documentative when you see how ugly this is
mosly in all from C derived languages.

Cor

"GY2" <2m*******@wherever.comschreef in bericht
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>I writing some documentation and I want to describe a common code
structure which is used to step through all the items in a collection
(e.g. each file in a subdirectory) while applying more and more
restrictive filters so that only the desired items can fall all the way
through. This method is so obvious and common it must have a name. What is
it or at least, what is the best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next


Nov 8 '06 #15

David Anton wrote:
We'll have to agree to disagree then. I find 'Select Case' more appropriate
where you care about many possible values of an expression.
Yes, which is the case in the OPs given example.

B.

Nov 8 '06 #16
Just to add another voice to the cacophony,
sometimes you just HAVE to use nested Ifs.

But with VB2005, you can also use the new
OrElse and put all of those together.
Like C#'s usage of Else, it will stop
evaluating options when it hits a false one.

For Each [file or whatever] In [some collection]
If [test 1] _
OrElse [test 2] _
OrElse [test 3] Then
[Found it]
End If
Next

Of course, this assumes you don't care which test
it passed.

Robin S.

"GY2" <2m*******@wherever.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>I writing some documentation and I want to describe a common code structure
which is used to step through all the items in a collection (e.g. each file
in a subdirectory) while applying more and more restrictive filters so that
only the desired items can fall all the way through. This method is so
obvious and common it must have a name. What is it or at least, what is the
best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next

Nov 8 '06 #17
Please re-read the original post. The OP example shows 3 independent tests,
not 3 possible values of an expression.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"Brian Tkatch" wrote:
>
David Anton wrote:
We'll have to agree to disagree then. I find 'Select Case' more appropriate
where you care about many possible values of an expression.

Yes, which is the case in the OPs given example.

B.

Nov 8 '06 #18
GY2
Exactly.

"David Anton" <Da********@discussions.microsoft.comwrote in message
news:CB**********************************@microsof t.com...
Please re-read the original post. The OP example shows 3 independent
tests,
not 3 possible values of an expression.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"Brian Tkatch" wrote:
>>
David Anton wrote:
We'll have to agree to disagree then. I find 'Select Case' more
appropriate
where you care about many possible values of an expression.

Yes, which is the case in the OPs given example.

B.


Nov 8 '06 #19
David Anton wrote:
Please re-read the original post. The OP example shows 3 independent tests,
not 3 possible values of an expression.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"Brian Tkatch" wrote:

David Anton wrote:
We'll have to agree to disagree then. I find 'Select Case' more appropriate
where you care about many possible values of an expression.
Yes, which is the case in the OPs given example.

B.

I did re-read it before i replied:

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next

In this case there's only one "Found it". The assumption is that the
elses will feed the other cases. And that is perfect for a CASE
statement.

B.

Nov 9 '06 #20

RobinS wrote:
Just to add another voice to the cacophony,
sometimes you just HAVE to use nested Ifs.
Yes, sometimes. Most cases not.

B.

Nov 9 '06 #21
Again, I think you're assuming that the if then structure will only
test one variable. In this case you could rewrite it using a Select
Case statement. But with multiple variables if thens are clearly better
suited for this. Take the following adaptation of the OP's structure:

dim a, b, c as integer

a = 5
b = 7
c = 7

if a 4 then
if b 6 then
if c 6 then
msgbox("found it")
end if
end if
end if

How exactly would you rewrite this with a select case?

Thanks,

Seth Rowe
Brian Tkatch wrote:
David Anton wrote:
Please re-read the original post. The OP example shows 3 independent tests,
not 3 possible values of an expression.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"Brian Tkatch" wrote:
>
David Anton wrote:
We'll have to agree to disagree then. I find 'Select Case' more appropriate
where you care about many possible values of an expression.
>
Yes, which is the case in the OPs given example.
>
B.
>
>


I did re-read it before i replied:

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next

In this case there's only one "Found it". The assumption is that the
elses will feed the other cases. And that is perfect for a CASE
statement.

B.
Nov 9 '06 #22
For what you have shown, I would suggest "andalso", i.e.,

if test1 andalso test2 andalso test3 then

end if

--
Dennis in Houston
"GY2" wrote:
I writing some documentation and I want to describe a common code structure
which is used to step through all the items in a collection (e.g. each file
in a subdirectory) while applying more and more restrictive filters so that
only the desired items can fall all the way through. This method is so
obvious and common it must have a name. What is it or at least, what is the
best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next

Nov 9 '06 #23
GY2
Well, the code has already been written in VB 6 years ago. All I'm trying do
to is document it and find out what the name of this kind of structure is.
Thanks, though. It's an interesting discussion.

"Dennis" <De****@discussions.microsoft.comwrote in message
news:CE**********************************@microsof t.com...
For what you have shown, I would suggest "andalso", i.e.,

if test1 andalso test2 andalso test3 then

end if

--
Dennis in Houston
"GY2" wrote:
>I writing some documentation and I want to describe a common code
structure
which is used to step through all the items in a collection (e.g. each
file
in a subdirectory) while applying more and more restrictive filters so
that
only the desired items can fall all the way through. This method is so
obvious and common it must have a name. What is it or at least, what is
the
best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next


Nov 9 '06 #24
If you are using VB 2005, you could rewrite this as

For Each [file or whatever] In [some collection]
if not [test 1] then Continue For
if not [test 2] then Continue For
...
[Found it]
Next

This has the benefit of eliminating the confusion that results when adding
an additional test. If you don't have VB 2005, I would rewrite as

For Each [file or whatever] In [some collection]
if passesfilters(file) then [Found it]
Next

Private function PassesFilters(file as object) as boolean
if not [test 1] then return false
if not [test 2] then return false
if not [test 3] then return false
return true
end function

Again, this eliminates the issue of screwing up the nesting when you change
the number or nature of the tests.

Mike.

"GY2" <2m*******@wherever.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
I writing some documentation and I want to describe a common code
structure
which is used to step through all the items in a collection (e.g. each
file
in a subdirectory) while applying more and more restrictive filters so
that
only the desired items can fall all the way through. This method is so
obvious and common it must have a name. What is it or at least, what is
the
best (short) way to describe it?

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next


Nov 9 '06 #25

rowe_newsgroups wrote:
Again, I think you're assuming that the if then structure will only
test one variable. In this case you could rewrite it using a Select
Case statement. But with multiple variables if thens are clearly better
suited for this. Take the following adaptation of the OP's structure:

dim a, b, c as integer

a = 5
b = 7
c = 7

if a 4 then
if b 6 then
if c 6 then
msgbox("found it")
end if
end if
end if

How exactly would you rewrite this with a select case?

Thanks,

Seth Rowe
Brian Tkatch wrote:
David Anton wrote:
Please re-read the original post. The OP example shows 3 independent tests,
not 3 possible values of an expression.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
>
>
"Brian Tkatch" wrote:
>

David Anton wrote:
We'll have to agree to disagree then. I find 'Select Case' more appropriate
where you care about many possible values of an expression.

Yes, which is the case in the OPs given example.

B.

I did re-read it before i replied:

For Each [file or whatever] In [some collection]
If [test 1] Then
If [test 2] Then
If [test 3] Then
[Found it]
End If
End If
End If
Next

In this case there's only one "Found it". The assumption is that the
elses will feed the other cases. And that is perfect for a CASE
statement.

B.
Again, I think you're assuming that the if then structure will only
test one variable. In this case you could rewrite it using a Select
Yes, i was assuming one variable. That is the usual case.

B.

Nov 9 '06 #26

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

226
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type...
16
by: Jason | last post by:
Hey, I'm an experience programmer but new to Python. I'm doing a simple implementation of a field morphing techinique due to Beier and Neely (1992) and I have the simple case working in Python...
25
by: chad | last post by:
I am writing a program to do some reliability calculations that require several nested for-loops. However, I believe that as the models become more complex, the number of required for-loops will...
9
by: datastructure | last post by:
Copyright (c) 2003 by James J. Perry. All Rights Reserved. char Square::validList = {'r', 'g', 'b'}; //missing an element, is 0 int Square::numValues = 3; Square::Square() { value =...
46
by: Neptune | last post by:
Hello. I am working my way through Zhang's "Teach yourself C in 24 hrs (2e)" (Sam's series), and for nested loops, he writes (p116) "It's often necessary to create a loop even when you are...
10
by: Roshawn | last post by:
Hi, I am experimenting with nested For...Next loops. My code looks like this: Dim i as Byte Dim itm as Byte For i = 0 to 9 For itm = 0 to 9 'code omitted
5
by: =?Utf-8?B?QUEyZTcyRQ==?= | last post by:
Could someone give me a simple example of nested scope in C#, please? I've searched Google for this but have not come up with anything that makes it clear. I am looking at the ECMA guide and...
13
by: Fredrik Lundh | last post by:
Patrol Sun wrote: so why exactly are you trying to nest 20 or 100 for-in loops? </F>
8
by: Nathan Sokalski | last post by:
I have several nested For loops, as follows: For a As Integer = 0 To 255 For b As Integer = 0 To 255 For c As Integer = 0 To 255 If <Boolean ExpressionThen <My CodeElse Exit For Next If Not...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.