IF/ELSE logic Examples

Example 1: IF statements from earlier versions of WinCross (WinCross 10.0 and earlier) will still work.

 

IF QA1_1 (10) & QB1_2 (10) & QC1_3 (10) ASSIGN TEST1 = (41)

IF QA1_1 (9)  & QB1_2 (9)  & QC1_3 (9)  ASSIGN TEST1 = (42)

 

IF QA1_1 (10) & QB1_2 (10) & QC1_3 (10) ASSIGN TEST2 = (1)

IF QA1_1 (9)  & QB1_2 (9)  & QC1_3 (9)  ASSIGN TEST2 = (2)

 

 

Example 2: IF/ELSE IF/ELSE with one line of code each (Don't need ENDIF if last ELSE clause is on same line as ELSE)

 

IF QA1_1 (10) & QB1_2 (10) & QC1_3 (10)

  ASSIGN TEST1 = (41)

ELSE IF QA1_1 (9) & QB1_2 (9) & QC1_3 (9)

  ASSIGN TEST1 = (42)

ELSE ASSIGN TEST1 = (43)

 

 

Example 3: IF/ELSE IF/ELSE with blocks of code (ENDIF needed due to block of code after ELSE)

 

IF QA1_1 (10) & QB1_2 (10) & QC1_3 (10)

   ASSIGN TEST1 = (41)

   ASSIGN TEST2 = (1)

ELSE IF QA1_1 (9) & QB1_2 (9) & QC1_3 (9)

   ASSIGN TEST1 = (42)

   ASSIGN TEST2 = (2)

ELSE

   ASSIGN TEST1 = (43)

   COMPUTE TEST5 = 3 – TEST1

ENDIF

 

 

Example 4: IF with block of code needs ENDIF

 

IF QA1_1 (7) & QB1_2 (7) & QC1_3 (7)

   ASSIGN TEST1 = (43)

   ASSIGN TEST2 = (5)

ENDIF

 

 

Example 5: IF/ELSE embedded in more IF/ELSE. Need to use block code with ENDIF so we know which ELSE goes with which IF

IF QA1_1 (10)

  IF QB1_2 (10)

    IF QC1_3 (10)

      IF QD1_4 (10)

        IF QE1_5 (10)

          IF QF1_6 (10)

            IF QG1_7 (10)

              IF QH1_8 (10)

                IF QI1_9 (10)

                  IF QJ1_10 (10)

                    ASSIGN TEST6 = (100)

                  ELSE  

                    ASSIGN TEST6 = (90)

                  ENDIF

                ELSE  

                  ASSIGN TEST6 = (80)

                ENDIF

              ELSE  

                ASSIGN TEST6 = (70)

              ENDIF

            ELSE  

              ASSIGN TEST6 = (60)

            ENDIF

          ELSE  

            ASSIGN TEST6 = (50)

          ENDIF

        ELSE  

          ASSIGN TEST6 = (40)

        ENDIF

      ELSE  

        ASSIGN TEST6 = (30)

      ENDIF

    ELSE  

      ASSIGN TEST6 = (20)

    ENDIF

  ELSE  

    ASSIGN TEST6 = (10)

  ENDIF

ELSE  

  ASSIGN TEST6 = (0)

ENDIF

Related topics:

IF/ELSE logic