As Justin Israel said, you can probably scan them to int and test them as 
ints.

However, if you *really* need them to be parsed as string, this will help 
your runtime, at the cost of constant overhead:
var (
  valueSet = map[string]struct{}{
    "1":nil,
    "2":nil,
    "3":nil,
    ....
    "15":nil,
  }
)

func checkValue(s string) bool {
  _, ok := valueSet[s]
  return ok
}

func fix() {
  if checkValue(x) {
    ....
  }
  ....
}



On Tuesday, January 22, 2019 at 6:40:52 AM UTC+8, John wrote:
>
> Dear Gophers,
>
> I have recently made a project of Connect Five. When the imput is wrong it 
> will have a goroutine problem that says something about out of index, as my 
> game win function depends on if the x = b and x+1 = b and so on. But if the 
> imput is not 1,2 1,3 and so on, or it is over 15, 15 it will be wrong. I 
> made a solution of creating a function like this: 
>
> func fix() {
> if x == "1"|| x == "2"|| x == "3"|| x == "4"|| x == "5"|| x == "6"|| x == 
> "7"|| x == "8"|| x == "9"|| x == "10"|| x == "11"|| x == "12"|| x == "13"|| 
> x == "14"|| x == "15" {
> if y == "1"|| y == "2"|| y == "3"|| y == "4"|| y == "5"|| y == "6"|| y == 
> "7"|| y == "8"|| y == "9"|| y == "10"|| y == "11"|| y == "12"|| y == "13"|| 
> y == "14"|| y == "15" {
> blwi()
> }  else {
> showBoard()
> fmt.Println("Sorry you had entered wrong please enter again")
> fmt.Scanln(&x,&y)
> fix()
> }
> }
>
> It for some reason won't work. So I wonder if any of you can help me 
> correct the function and simplify it. (it goes right between the imput and 
> the win function.)
>   
>              
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to