Go is a open-source programming language developed at Google by Robert Griesemer, Rob Pike, and Ken Thompson. Go is similar to C syntactically but with CSP style concurrency and many features of other robust programming language. Often refereed to as Golang because of the domain name, this language also has the If/else conditions. Usually the If/else/else if condition when written with one condition makes the program lengthy and increases the complexity thus we can combine two conditions. The conditions can be combined in the following ways :-
Using &&(AND) Operator
The And (&&) is a way of combining conditional statement has the following syntax:
if (condition1) && (condition2) {
......
}
Here, condition1 represents the first condition and condition2 represents the second condition. The && statement combines the conditions and gives the results in the following way:
- If condition1 is True and condition2 is also True, the result is True.
- If condition1 is True and condition2 is False, the result is False.
- If condition1 is False and condition2 is True, the result is False.
- If condition1 is False and condition2 is also False, the result is False.
Go
package main
import "fmt"
func main() {
time := 18
if time > 10 && time < 18 {
fmt.Println( "Time for work" )
}
}
|
Using OR operator
The OR way of combining conditional statement has the following syntax:
if (condition1) || (condition2) {
.......
}
Here, condition1 represents the first condition and condition2 represents the second condition. The || statement combines the conditions and gives the results in the following way:
- If condition1 is True and condition2 is also True, the result is True.
- If condition1 is True and condition2 is False, the result is True.
- If condition1 is False and condition2 is True, the result is True.
- If condition1 is False and condition2 is also False, the result is False.
Go
package main
import "fmt"
func main() {
time := 14
if time > 10 || time < 12 {
fmt.Println( "Hello geeks" )
}
}
|
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
08 Jun, 2020
Like Article
Save Article