Похожие чаты

For i :=1 ; i<100 ; i++ { switch

i {
case i%3 == 0 && i%5==0:fmt.Println("FizzBuzz")
case i%3 == 0:fmt.Println("Fizz")
case i%5 == 0:fmt.Println("Buzz")
default: fmt.Println(i)
}



errors :
/main.go:39:3: cannot use i % 3 == 0 && i % 5 == 0 (type bool) as type int
./main.go:40:3: cannot use i % 3 == 0 (type untyped bool) as type int
./main.go:41:3: cannot use i % 5 == 0 (type untyped bool) as type int



hey guys , i've just started learning go a week ago . what is the problem with this code ?

8 ответов

12 просмотров

You can't assign condition to case statement, if you want to give condition then use if - else

"Mahdi"- Автор вопроса
DΛNTΣ
You can't assign condition to case statement, if y...

aha . so in case we want to check for multiple conditions in our code we should use if , else if , else but in case that we wanna do something base on the value of a variable , we can use swich case thanks man

"Mahdi"
aha . so in case we want to check for multiple con...

Yp exactly, here's an example also if you want.

play.golang.org

DΛNTΣ
You can't assign condition to case statement, if y...

of course you can: https://play.golang.org/p/xacceowwwJv

"Mahdi"- Автор вопроса
Roman Sharkov
of course you can: https://play.golang.org/p/xacce...

wow . thanks Roman . the only difference is : we should not pass the variable to the switch statement . so if we pass a variable name to the switch statement , then we should just compare the value of that variable ( we can't evaluate some condition ) but , if we don't pass any variable to switch , then we can evaluate as much as condition .

Roman Sharkov
of course you can: https://play.golang.org/p/xacce...

Aah... Never knew this existed, looks interesting but as far as readability goes I would preffer using if else for conditionals ig...

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта