Похожие чаты

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 ответов

10 просмотров

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...

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

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

Ready for some fun AND a chance to win TKO Tokens? Join us for exciting minigames in our Telegram group! 🕒 Don’t miss out—games start on today 25 October 2024, at 8 PM! Ge...
Milkyway | Tokocrypto
255
In 2022, ENF, a renowned corporation once known for its commitment to innovation and leadership, began to falter. For years, the company had been the face of cutting-edge tech...
chensae
1
Мужики и девушки, привет) в Вelphi xe7 в настройках во вкладке "Editor Options" далее " Color" есть список: "Elements", открыв который мы можем настраивать отображение разных...
Kraszx
14
Добрый вечер. Есть вопрос, а может и предложение. Был у меня диалог в другой группе о делфи и я задался вопросом: "А нельзя ли в делфи цвет //коментария и {комментария} сде...
Kraszx
24
function LoadMemoryFromInet2( f:TMemoryStream; const url:string; var e:string ):Boolean; var http:TIdHttp; LHandler: TIdSSLIOHandlerSocketOpenSSL;begin Result := fals...
Александр Смоляков
1
is that okay?
Samurai 🇯🇵
21
VIP-392 [zkSync] New native USDC market in the Core pool Summary If passed, following the Community proposal “Support native USDC on Venus Core Pool of ZKSync Era” and the a...
Venus Announcements
1
How about the project bro Likes the community not that active ?
🅿️abby_FX
19
Я вот подумал. SSE выполняет операции максимум с 64-битной точностью. А FPU - всегда с 80-битной. Разве не должно быть FPU точнее тогда?
The Bird of Hermes
13
Guys, Donald Trump or Kamala Harris? It does not matter for Bitcoin in the long run!! 2020 Election: After Joe Biden's victory in November 2020, Bitcoin steadily rose from...
Sabah Shabu
3
Карта сайта