- F# Basic Tutorial
- F# - Home
- F# - Overview
- F# - Environment Setup
- F# - Program Structure
- F# - Basic Syntax
- F# - Data Types
- F# - Variables
- F# - Operators
- F# - Decision Making
- F# - Loops
- F# - Functions
- F# - Strings
- F# - Options
- F# - Tuples
- F# - Records
- F# - Lists
- F# - Sequences
- F# - Sets
- F# - Maps
- F# - Discriminated Unions
- F# - Mutable Data
- F# - Arrays
- F# - Mutable Lists
- F# - Mutable Dictionary
- F# - Basic I/O
- F# - Generics
- F# - Delegates
- F# - Enumerations
- F# - Pattern Matching
- F# - Exception Handling
- F# - Classes
- F# - Structures
- F# - Operator Overloading
- F# - Inheritance
- F# - Interfaces
- F# - Events
- F# - Modules
- F# - Namespaces
- F# Useful Resources
- F# - Quick Guide
- F# - Useful Resources
- F# - Discussion
F# - Boolean Operators
The following table shows all the Boolean operators supported by F# language. Assume variable A holds true and variable B holds false, then −
Operator | Description | Example |
---|---|---|
&& | Called Boolean AND operator. If both the operands are non-zero, then condition becomes true. | (A && B) is false. |
|| | Called Boolean OR Operator. If any of the two operands is non-zero, then condition becomes true. | (A || B) is true. |
not | Called Boolean NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. | not (A && B) is true. |
Example
let mutable a : bool = true; let mutable b : bool = true; if ( a && b ) then printfn "Line 1 - Condition is true" else printfn "Line 1 - Condition is not true" if ( a || b ) then printfn "Line 2 - Condition is true" else printfn "Line 2 - Condition is not true" (* lets change the value of a *) a <- false if ( a && b ) then printfn "Line 3 - Condition is true" else printfn "Line 3 - Condition is not true" if ( a || b ) then printfn "Line 4 - Condition is true" else printfn "Line 4 - Condition is not true"
When you compile and execute the program, it yields the following output −
Line 1 - Condition is true Line 2 - Condition is true Line 3 - Condition is not true Line 4 - Condition is true
fsharp_operators.htm
Advertisements