B
Bob
Hi,
i'm not sure to understand how a value is returned from a function.
Look at this code below about a simple function that compares a value with
values 1 from 5.
I thought: if the passed value (x = test(?)) is not from 1 to 5, then the
return = -1. That's ok.
If not, the function will return value z, but at the end of the for/next
loop, the other return (return -1) will also be executed, no? The line
'return -1' is outside of the loop and will be executed in all cases?
Thanks
Bob
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim x As Integer
x = test(6)
Response.Write(x)
End Sub
Function test(ByVal z As Integer) As Integer
Dim i As Integer
For i = 1 To 5
If z = i Then
Return z
End If
Next
Return -1
End Function
i'm not sure to understand how a value is returned from a function.
Look at this code below about a simple function that compares a value with
values 1 from 5.
I thought: if the passed value (x = test(?)) is not from 1 to 5, then the
return = -1. That's ok.
If not, the function will return value z, but at the end of the for/next
loop, the other return (return -1) will also be executed, no? The line
'return -1' is outside of the loop and will be executed in all cases?
Thanks
Bob
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim x As Integer
x = test(6)
Response.Write(x)
End Sub
Function test(ByVal z As Integer) As Integer
Dim i As Integer
For i = 1 To 5
If z = i Then
Return z
End If
Next
Return -1
End Function