The following is common in any programming language.
foreach(.....)
{
if(...)
....
}
I wonder whether it is a good programming practice to use the following. I know it works, but it looks little bit untidy.
if(....)
{
foreach(...)
{
...
}
}
Iterating over a collection when some condition evaluates to true is the requirement. But I have never seen this in any kind of sample codes. In a nutshell, I have never noticed such in codes written by other people. But this works and gives me what I want. But I want to avoid writing a loop inside a if block.
Can someone point out an alternative to this ?
Aucun commentaire:
Enregistrer un commentaire