Home

Conditional Statements: Disjunctions

   

Description

A Boolean disjunction is a conditional statement where you combine more than one condition but only one of the conditions needs to be true for the whole operation to be true. This operation is performed using the Boolean "Or" operator represented as ||. The primary formula to follow is:

Condition1 || Condition2

The operation works as follows:

  • If at least one of the individual conditions is true, the whole operation produces a true result
  • If all operations are false, only then will the whole operation produce a false result

Here is an example:

open System
open System.Windows.Forms 

let hotelRoom = new Form()
hotelRoom.Width  <- 305
hotelRoom.Height <- 190
hotelRoom.Text   <- "Hotel Management"

let lblDesiredRoomType = new Label()
lblDesiredRoomType.Left  <- 23
lblDesiredRoomType.Top   <- 19
lblDesiredRoomType.Width <- 122
lblDesiredRoomType.Text  <- "Type of Room Desired:"
hotelRoom.Controls.Add(lblDesiredRoomType)

let cbxRoomTypes = new ComboBox()
cbxRoomTypes.Left  <- 160
cbxRoomTypes.Top   <-  16
cbxRoomTypes.Width <- 121
cbxRoomTypes.Items.AddRange([| "Studio Suite"; "Conference Room"; "Standard Bedroom" |])
hotelRoom.Controls.Add(cbxRoomTypes)

let pnlBedrooms = new Panel()
pnlBedrooms.Left   <-  2
pnlBedrooms.Top    <- 43
pnlBedrooms.Width  <- 296
pnlBedrooms.Height <- 114
pnlBedrooms.Visible <- false

let lblBedTypes = new Label()
lblBedTypes.Left <- 21
lblBedTypes.Top  <- 25
lblBedTypes.Width <- 80
lblBedTypes.Text <- "Bed Type(s):"
pnlBedrooms.Controls.Add(lblBedTypes)

let txtBedTypes = new TextBox()
txtBedTypes.Left  <- 158
txtBedTypes.Top   <-  22
txtBedTypes.Width <- 121
txtBedTypes.Text  <- "Queen"
pnlBedrooms.Controls.Add(txtBedTypes)

let lblBedroomDailyRate = new Label()
lblBedroomDailyRate.Left <- 21
lblBedroomDailyRate.Top  <- 60
lblBedroomDailyRate.Width <- 80
lblBedroomDailyRate.Text <- "Daily Rate:"
pnlBedrooms.Controls.Add(lblBedroomDailyRate)

let txtBedroomDailyRate = new TextBox()
txtBedroomDailyRate.Left  <- 158
txtBedroomDailyRate.Top   <-  61
txtBedroomDailyRate.Width <- 121
txtBedroomDailyRate.Text  <- "104.50"
pnlBedrooms.Controls.Add(txtBedroomDailyRate)
hotelRoom.Controls.Add(pnlBedrooms)

let pnlConferenceRoomDetails = new Panel()
pnlConferenceRoomDetails.Visible <- false
pnlConferenceRoomDetails.Left    <-   2
pnlConferenceRoomDetails.Top     <-  43
pnlConferenceRoomDetails.Width   <- 296
pnlConferenceRoomDetails.Height  <- 114

let lblNumberOfSeats = new Label()
lblNumberOfSeats.Left <- 21
lblNumberOfSeats.Top  <- 11
lblNumberOfSeats.Text <- "Number of Seats"
pnlConferenceRoomDetails.Controls.Add(lblNumberOfSeats)

let txtNumberOfSeats = new TextBox()
txtNumberOfSeats.Left  <- 158
txtNumberOfSeats.Top   <-   8
txtNumberOfSeats.Width <- 121
txtNumberOfSeats.Text  <- "466"
pnlConferenceRoomDetails.Controls.Add(txtNumberOfSeats)

let chkVideoConference = new CheckBox()
chkVideoConference.Left <- 19
chkVideoConference.Top  <- 40
chkVideoConference.Width  <- 124
chkVideoConference.Checked <- true
chkVideoConference.Text <- "Video Conference"
pnlConferenceRoomDetails.Controls.Add(chkVideoConference)

let chkProjector = new CheckBox()
chkProjector.Left    <- 187
chkProjector.Top     <-  40
chkProjector.Checked <- true
chkProjector.Text    <- "LCD Projector"
pnlConferenceRoomDetails.Controls.Add(chkProjector)

let lblConferenceDailyRate = new Label()
lblConferenceDailyRate.Left <- 21
lblConferenceDailyRate.Top  <- 82
lblConferenceDailyRate.Text <- "Daily Rate:"
pnlConferenceRoomDetails.Controls.Add(lblConferenceDailyRate)

let txtConferenceDailyRate = new TextBox()
txtConferenceDailyRate.Left  <- 158
txtConferenceDailyRate.Top   <-  79
txtConferenceDailyRate.Width <- 121
txtConferenceDailyRate.Text  <- "625.00"
pnlConferenceRoomDetails.Controls.Add(txtConferenceDailyRate)
hotelRoom.Controls.Add(pnlConferenceRoomDetails)

let cbxRoomTypesSelectedIndexChanged(e) =
    if cbxRoomTypes.Text = "Standard Bedroom" || cbxRoomTypes.Text = "Studio Suite" then
        pnlBedrooms.Visible <- true
        pnlConferenceRoomDetails.Visible <- false
    else
        pnlBedrooms.Visible <- false
        pnlConferenceRoomDetails.Visible <- true
cbxRoomTypes.SelectedIndexChanged.Add(cbxRoomTypesSelectedIndexChanged)

Application.Run(hotelRoom)

Here is an example or executing the program:

Boolean Disjunction Boolean Disjunction
Boolean Disjunction Boolean Disjunction

As mentioned for the conjunction, it is a good idea to include each Boolean operation in its parentheses. Here is an example:

let cbxRoomTypesSelectedIndexChanged(e) =
    if (cbxRoomTypes.Text = "Standard Bedroom") || (cbxRoomTypes.Text = "Studio Suite") then
        pnlBedrooms.Visible <- true
        pnlConferenceRoomDetails.Visible <- false
    else
        pnlBedrooms.Visible <- false
        pnlConferenceRoomDetails.Visible <- true

You can create a conditional statement that includes as many disjunctions as you want. The formula to follow is:

Condition1 || Condition2 || . . . || Condition_n

The rule is the same: If any one of the individual operations is true, the whole operation is true. The whole operation is false only if all of the operations are false.

     
     
 

Home Copyright © 2015, FunctionX Home