How to resolve the algorithm Conditional structures step by step in the Smalltalk programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Conditional structures step by step in the Smalltalk programming language

Table of Contents

Problem Statement

List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include if-then-else and switch. Less common are arithmetic if, ternary operator and Hash-based conditionals. Arithmetic if allows tight control over computed gotos, which optimizers have a hard time to figure out.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Conditional structures step by step in the Smalltalk programming language

Source code in the smalltalk programming language

 balance > 0
     ifTrue: [Transcript cr; show: 'still sitting pretty!'.]
     ifFalse: [Transcript cr; show: 'No money till payday!'.].

 balance < 10 ifTrue:[ self goGetSomeMoney ].

 balance > 1000 ifTrue:[ self beHappy ].

 (balance < 10) 
    ifFalse:[ self gotoHappyHour ]
    ifTrue:[ self noDrinksToday ].

abs := x > 0 ifTrue: [ x ] ifFalse: [ x negated ]

...
trueAction := [ ... do something ].
falseAction := [ ... do something else ...].
...
abs := x > 0 ifTrue:trueAction ifFalse:falseAction. "3)"

|x|
x := 1.
value :=
    x caseOf: {
       [1]->['one'].
       [2]->['two'].
       [3]->['three']
    }
    otherwise:['none of them'].

  

You may also check:How to resolve the algorithm Iterated digits squaring step by step in the zkl programming language
You may also check:How to resolve the algorithm Arrays step by step in the Perl programming language
You may also check:How to resolve the algorithm Partial function application step by step in the TXR programming language
You may also check:How to resolve the algorithm Nonogram solver step by step in the Go programming language
You may also check:How to resolve the algorithm File size step by step in the FutureBasic programming language