# Golang Program to print all integers between a range that aren't divisible by either 2 or 3

Go ProgrammingServer Side ProgrammingProgramming

#### Cyber Security : Go from Zero to Hero

Most Popular

60 Lectures 5.5 hours

#### Master C and Embedded C Programming- Learn as you go

66 Lectures 5.5 hours

#### C Programming from scratch- Master C Programming

Best Seller

60 Lectures 8 hours

Let's assume the range is from 0 to 50. We have to print all the integers that aren't divisible by either 2 or 3.

## Steps

• Use a for loop ranging from 0 to 50.
• Then, use an if statement to check if the number isn't divisible by both 2 and 3.
• Print the numbers satisfying the condition.

## Explanation

• The for loop ranges from 0 to 50.
• The number is divided by 2 and 3.
• If the remainder ≠ 0, the number isn't divisible by either 2 and 3.
• The number satisfying the condition is printed.

## Example

Live Demo

package main
import "fmt"
func main(){
for i:=1; i<=50; i++{
if !(i % 2 == 0 || i % 3 == 0){
fmt.Println(i)
}
}
}

## Output

1
5
7
11
13
17
19
23
25
29
31
35
37
41
43
47
49