< operator in Go lang [closed]
Well I am a newby in Go lang, but this doesn't make sense to me:
package main
import (
"fmt"
"log"
)
var rectLen, rectWidth float64 = 0, 0
func init() {
fmt.Println("init is initialized")
if rectLen < 0 {
log.Fatal("rectLen smaller than 0")
}
if rectWidth < 0 {
log.Fatal("rectWidht smaller than 0")
}
}
func main() {
fmt.Println("Main is initialized")
fmt.Println(rectLen, rectWidth )
}
This will print out:
init is initialized
Main is initialized
0 0
Why is 0 and 0 printed out when my init function is "guarding" that my rectLen, rectWidth variables should be strictly greater than 0?
If I change the values to something less than 0, it works fine, I get:
init is initialized
2009/11/10 23:00:00 rectLen smaller than 0
Thanks!
go
closed as off-topic by Volker, Flimzy, peterSO, ThunderCat, gnat Dec 30 '18 at 14:08
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Volker, Flimzy, peterSO, ThunderCat
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
Well I am a newby in Go lang, but this doesn't make sense to me:
package main
import (
"fmt"
"log"
)
var rectLen, rectWidth float64 = 0, 0
func init() {
fmt.Println("init is initialized")
if rectLen < 0 {
log.Fatal("rectLen smaller than 0")
}
if rectWidth < 0 {
log.Fatal("rectWidht smaller than 0")
}
}
func main() {
fmt.Println("Main is initialized")
fmt.Println(rectLen, rectWidth )
}
This will print out:
init is initialized
Main is initialized
0 0
Why is 0 and 0 printed out when my init function is "guarding" that my rectLen, rectWidth variables should be strictly greater than 0?
If I change the values to something less than 0, it works fine, I get:
init is initialized
2009/11/10 23:00:00 rectLen smaller than 0
Thanks!
go
closed as off-topic by Volker, Flimzy, peterSO, ThunderCat, gnat Dec 30 '18 at 14:08
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Volker, Flimzy, peterSO, ThunderCat
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
Well I am a newby in Go lang, but this doesn't make sense to me:
package main
import (
"fmt"
"log"
)
var rectLen, rectWidth float64 = 0, 0
func init() {
fmt.Println("init is initialized")
if rectLen < 0 {
log.Fatal("rectLen smaller than 0")
}
if rectWidth < 0 {
log.Fatal("rectWidht smaller than 0")
}
}
func main() {
fmt.Println("Main is initialized")
fmt.Println(rectLen, rectWidth )
}
This will print out:
init is initialized
Main is initialized
0 0
Why is 0 and 0 printed out when my init function is "guarding" that my rectLen, rectWidth variables should be strictly greater than 0?
If I change the values to something less than 0, it works fine, I get:
init is initialized
2009/11/10 23:00:00 rectLen smaller than 0
Thanks!
go
Well I am a newby in Go lang, but this doesn't make sense to me:
package main
import (
"fmt"
"log"
)
var rectLen, rectWidth float64 = 0, 0
func init() {
fmt.Println("init is initialized")
if rectLen < 0 {
log.Fatal("rectLen smaller than 0")
}
if rectWidth < 0 {
log.Fatal("rectWidht smaller than 0")
}
}
func main() {
fmt.Println("Main is initialized")
fmt.Println(rectLen, rectWidth )
}
This will print out:
init is initialized
Main is initialized
0 0
Why is 0 and 0 printed out when my init function is "guarding" that my rectLen, rectWidth variables should be strictly greater than 0?
If I change the values to something less than 0, it works fine, I get:
init is initialized
2009/11/10 23:00:00 rectLen smaller than 0
Thanks!
go
go
asked Dec 29 '18 at 11:00
Andrei BAndrei B
1
1
closed as off-topic by Volker, Flimzy, peterSO, ThunderCat, gnat Dec 30 '18 at 14:08
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Volker, Flimzy, peterSO, ThunderCat
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by Volker, Flimzy, peterSO, ThunderCat, gnat Dec 30 '18 at 14:08
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Volker, Flimzy, peterSO, ThunderCat
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Because <
is not the same as “equal to”. Try changing your operators to <=
. This should fire only if your value is less than OR equal to 0
Yep, I am dumb. Thanks! :))
– Andrei B
Dec 29 '18 at 11:08
1
@AndreiB you’re not dumb, your just new. I’ve been programming for 17 years and still make mistakes and google-fu everyday. ! Hang in there
– Flightdoc5242
Dec 29 '18 at 11:10
The day we programmers stop making programming mistakes is the day we stop programming :)
– Lasse Vågsæther Karlsen
Dec 29 '18 at 12:01
Wow...I didn't expect such kind words.
– Andrei B
Dec 30 '18 at 7:46
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Because <
is not the same as “equal to”. Try changing your operators to <=
. This should fire only if your value is less than OR equal to 0
Yep, I am dumb. Thanks! :))
– Andrei B
Dec 29 '18 at 11:08
1
@AndreiB you’re not dumb, your just new. I’ve been programming for 17 years and still make mistakes and google-fu everyday. ! Hang in there
– Flightdoc5242
Dec 29 '18 at 11:10
The day we programmers stop making programming mistakes is the day we stop programming :)
– Lasse Vågsæther Karlsen
Dec 29 '18 at 12:01
Wow...I didn't expect such kind words.
– Andrei B
Dec 30 '18 at 7:46
add a comment |
Because <
is not the same as “equal to”. Try changing your operators to <=
. This should fire only if your value is less than OR equal to 0
Yep, I am dumb. Thanks! :))
– Andrei B
Dec 29 '18 at 11:08
1
@AndreiB you’re not dumb, your just new. I’ve been programming for 17 years and still make mistakes and google-fu everyday. ! Hang in there
– Flightdoc5242
Dec 29 '18 at 11:10
The day we programmers stop making programming mistakes is the day we stop programming :)
– Lasse Vågsæther Karlsen
Dec 29 '18 at 12:01
Wow...I didn't expect such kind words.
– Andrei B
Dec 30 '18 at 7:46
add a comment |
Because <
is not the same as “equal to”. Try changing your operators to <=
. This should fire only if your value is less than OR equal to 0
Because <
is not the same as “equal to”. Try changing your operators to <=
. This should fire only if your value is less than OR equal to 0
answered Dec 29 '18 at 11:05
Flightdoc5242Flightdoc5242
1127
1127
Yep, I am dumb. Thanks! :))
– Andrei B
Dec 29 '18 at 11:08
1
@AndreiB you’re not dumb, your just new. I’ve been programming for 17 years and still make mistakes and google-fu everyday. ! Hang in there
– Flightdoc5242
Dec 29 '18 at 11:10
The day we programmers stop making programming mistakes is the day we stop programming :)
– Lasse Vågsæther Karlsen
Dec 29 '18 at 12:01
Wow...I didn't expect such kind words.
– Andrei B
Dec 30 '18 at 7:46
add a comment |
Yep, I am dumb. Thanks! :))
– Andrei B
Dec 29 '18 at 11:08
1
@AndreiB you’re not dumb, your just new. I’ve been programming for 17 years and still make mistakes and google-fu everyday. ! Hang in there
– Flightdoc5242
Dec 29 '18 at 11:10
The day we programmers stop making programming mistakes is the day we stop programming :)
– Lasse Vågsæther Karlsen
Dec 29 '18 at 12:01
Wow...I didn't expect such kind words.
– Andrei B
Dec 30 '18 at 7:46
Yep, I am dumb. Thanks! :))
– Andrei B
Dec 29 '18 at 11:08
Yep, I am dumb. Thanks! :))
– Andrei B
Dec 29 '18 at 11:08
1
1
@AndreiB you’re not dumb, your just new. I’ve been programming for 17 years and still make mistakes and google-fu everyday. ! Hang in there
– Flightdoc5242
Dec 29 '18 at 11:10
@AndreiB you’re not dumb, your just new. I’ve been programming for 17 years and still make mistakes and google-fu everyday. ! Hang in there
– Flightdoc5242
Dec 29 '18 at 11:10
The day we programmers stop making programming mistakes is the day we stop programming :)
– Lasse Vågsæther Karlsen
Dec 29 '18 at 12:01
The day we programmers stop making programming mistakes is the day we stop programming :)
– Lasse Vågsæther Karlsen
Dec 29 '18 at 12:01
Wow...I didn't expect such kind words.
– Andrei B
Dec 30 '18 at 7:46
Wow...I didn't expect such kind words.
– Andrei B
Dec 30 '18 at 7:46
add a comment |