package main
import"fmt"
func main(){// var count,c int //定义变量不使用也会报错var count intvar flag bool
count=1//while(count<100) { //go没有whilefor count <100{
count++
flag =true;//注意tmp变量 :=for tmp:=2;tmp<count;tmp++{if count%tmp==0{
flag =false}}// 每一个 if else 都需要加入括号 同时 else 位置不能在新一行if flag ==true{
fmt.Println(count,"素数")}else{continue}}}
2.if ... else if ... else... 实例:
package main
import"fmt"
func main(){var age int=23if age ==25{
fmt.Println("true")}elseif age <25{
fmt.Println("too small")}else{
fmt.Println("too big")}}