IF

Conditional blocks are an important element of every programming language. The execution of jumps (go to) is not possible within CADINP as it is proven to be able to solve any problem without this feature. The conditional block is executed if the expression following the IF is greater than zero. You might want to use the logical expressions for this. Texts may be only compared with == and != operators, the comparison is case sensitive. As the complete string on both sides of the operator is considered, no parentheses are allowed, they are part of the strings.

! #1 is the control variable with possible values +1/-1
IF #1
   ! These lines are input when #1 > 0
   ! ...
ELSE
   ! These lines are input when #1 < 0 or = 0
   ! ...
ENDIF
IF #1==12
   ! These lines are input when #1 equals 12
   ! ...
ELSE
   ! These lines are input when #1 does not equal 12
   ! ...
ENDIF

The generation of a CASE construction is available by using a series of additional ELSEIF statements:

if (Condition_1)
   ....
elseif (Condition_2)
   ....
elseif (Condition_3)
   ....
else
   ....
endif

Example:

IF (#A < 0.3) ! condition 1
   LET#VALUE 0.50
ELSEIF (#A>1.0) ! or condition 2
   LET#VALUE 0.70
ELSE
   LET#VALUE 0.50+0.20*(#A-0.3) ! else this value
ENDIF

That means that only one possibility is chosen for VALUE depending on A.

Todo

add figure VALUE depending on A from Sof Basics manual

In special cases it is possible to create the following input which can be used in different SOFiSTiK environments with various versions:

IF (#VERSION>=2012)
   !....
ELSEIF (#VERSION==2010)
   !....
ELSE // older SOFiSTiK Releases
   !....
ENDIF

** Conditional blocks in CADINP. ** Block input will be closed with ENDIF ** The conditional block is executed if the expression following the IF is greater than zero (=true), in case of (=false) the value is 0.

Hint

It is not allowed to have any blanks inside the IF-condition

  • Exact comparison with == or <> do not work most of the time, because all CADINP variables will be saved as float numbers. For comparison please use always a small tolerance.

LET#VAL1 -26.184
LET#VAL2 -26.184
! True = 1, because values are exactly the same

LET#ERG1 (#VAL1==#VAL2)
@KEY N_DISP 2
LET#VAL2 @(4,py)

! False = 0, because values are not exactly the same
LET#ERG2 (#VAL1==#VAL2

! True = 1, because of tolerance
LET#ERG3 ABS(#VAL1-#VAL2)<0.01

Multiple conditions are possible with logical and & and respectively or |. Every single condition should be written with brackets ( ).

LET#ERG1 (1>0)&(2>0) ! true = 1
LET#ERG2 (1>0)&(2<0) ! false = 0
LET#ERG3 (1>0)|(2<0) ! true = 1
LET#ERG4 (1<0)|(2<0) ! false = 0

@KEY N_DISP 1
LOOP
   LET#PY @PY
   IF (#CDB_IER<1)&(ABS(#PY)>30)
      TXA value larger than 30 kN , PY = #(#PY,7.3) kN
   ENDIF
ENDLOOP #CDB_IER<2