Where is the exit?
-
I just take a look into my friend's code, then I found something confusing to me :confused: I have made some modifications here :
Private Function xxx(ByVal name As String) As Boolean
Dim xxxResult As Boolean = False
If name = "A" Then
' Lots of code here
Return xxxResult
Else
' Lots of code here
Return xxxResult
End If
' Lots of code again
Return xxxResult
Exit Function
End FunctionFinally, when I want to go back to my home, I still confused, the world is spinning in my head, there are so much doors. ;P
25160506848319
Yeah, that needs some GOTOs. :-D
-
Is this a modern Where's Wally?
red_moon wrote:
Where is the exit?
Private Function xxx(ByVal name As String) As Boolean
Dim xxxResult As Boolean = False
If name = "A" Then
' Lots of code here
Return xxxResult
Else
' Lots of code here
Return xxxResult
End If
' Lots of code again
Return xxxResult
Exit Function <------Its there just before the word function; Whats the prize?
End FunctionOk, so he's using multiple return points, and there is no requirement here for the Exit Function statement as it is at the end.
Dave Don't forget to rate messages!
Find Me On: Web|Facebook|Twitter|LinkedIn -
Yeah, that needs some GOTOs. :-D
Yeah - starting with "GOTO AProgrammingLanguageThanSpotsUnreachableCode"
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
Yeah - starting with "GOTO AProgrammingLanguageThanSpotsUnreachableCode"
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
I haven't met many compilers that do a good job at detecting unreachable statements, try this C# snippet:
public int unreachable(int a) {
if (a==1) return 2;
if (a!=1) return 3;
return 4;
}:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
I haven't met many compilers that do a good job at detecting unreachable statements, try this C# snippet:
public int unreachable(int a) {
if (a==1) return 2;
if (a!=1) return 3;
return 4;
}:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
That's just a
if..else..maybe
construct: we used to use them all the time in FORTRAN (because the compiler was such rubbish "maybe" would get executed sometimes). At least C# would spotpublic int unreachable(int a)
{
if (a==1)
return 2;
else
return 3;
return 4;
}Unlike some of the "coderzz" we have asking questions at the moment... :laugh:
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
Is this a modern Where's Wally?
red_moon wrote:
Where is the exit?
Private Function xxx(ByVal name As String) As Boolean
Dim xxxResult As Boolean = False
If name = "A" Then
' Lots of code here
Return xxxResult
Else
' Lots of code here
Return xxxResult
End If
' Lots of code again
Return xxxResult
Exit Function <------Its there just before the word function; Whats the prize?
End FunctionOk, so he's using multiple return points, and there is no requirement here for the Exit Function statement as it is at the end.
Dave Don't forget to rate messages!
Find Me On: Web|Facebook|Twitter|LinkedIndaveauld wrote:
Its there just before the word function; Whats the prize?
Check the code again. Will it come there to execute? How? ;P
Don't forget to Click on [Vote] and [Good Answer] on the posts that helped you.
Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets | Silverlight Tutorial
-
Is this a modern Where's Wally?
red_moon wrote:
Where is the exit?
Private Function xxx(ByVal name As String) As Boolean
Dim xxxResult As Boolean = False
If name = "A" Then
' Lots of code here
Return xxxResult
Else
' Lots of code here
Return xxxResult
End If
' Lots of code again
Return xxxResult
Exit Function <------Its there just before the word function; Whats the prize?
End FunctionOk, so he's using multiple return points, and there is no requirement here for the Exit Function statement as it is at the end.
Dave Don't forget to rate messages!
Find Me On: Web|Facebook|Twitter|LinkedIn -
I just take a look into my friend's code, then I found something confusing to me :confused: I have made some modifications here :
Private Function xxx(ByVal name As String) As Boolean
Dim xxxResult As Boolean = False
If name = "A" Then
' Lots of code here
Return xxxResult
Else
' Lots of code here
Return xxxResult
End If
' Lots of code again
Return xxxResult
Exit Function
End FunctionFinally, when I want to go back to my home, I still confused, the world is spinning in my head, there are so much doors. ;P
25160506848319
He codes for both Aristotlean and Bhuddist logic. In the vast majority of cases the black and white of Aristotle will hold true but never underestimate the differing shades of Bhuddist logic. Maybe.
-
I just take a look into my friend's code, then I found something confusing to me :confused: I have made some modifications here :
Private Function xxx(ByVal name As String) As Boolean
Dim xxxResult As Boolean = False
If name = "A" Then
' Lots of code here
Return xxxResult
Else
' Lots of code here
Return xxxResult
End If
' Lots of code again
Return xxxResult
Exit Function
End FunctionFinally, when I want to go back to my home, I still confused, the world is spinning in my head, there are so much doors. ;P
25160506848319
Most girls I've asked seem to think there is a very specific area that is an exit (making sure to note that it is not an entrance). In order to pass on this knowledge, I thought I'd let you know that "Return xxx..." is not an entrance.
-
daveauld wrote:
Its there just before the word function; Whats the prize?
Check the code again. Will it come there to execute? How? ;P
Don't forget to Click on [Vote] and [Good Answer] on the posts that helped you.
Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets | Silverlight Tutorial
There are chunks of code removed, so we cannot assume that there are no
Exit If
's anywhere. Also, if its VB6 there may also be someOn Error Resume Next
statements. (Or On Error Goto xyz
), Ah, those 'handy' statements! :doh: :)Dave Don't forget to rate messages!
Find Me On: Web|Facebook|Twitter|LinkedIn -
There are chunks of code removed, so we cannot assume that there are no
Exit If
's anywhere. Also, if its VB6 there may also be someOn Error Resume Next
statements. (Or On Error Goto xyz
), Ah, those 'handy' statements! :doh: :)Dave Don't forget to rate messages!
Find Me On: Web|Facebook|Twitter|LinkedInSo, it's depends on the whole code implementation... Without seeing the original code, it's not feasible to reply... :laugh:
Don't forget to Click on [Vote] and [Good Answer] on the posts that helped you.
Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets | Silverlight Tutorial