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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Conditional structures step by step in the Run BASIC 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 Run BASIC programming language

Source code in the run programming language

' Boolean Evaluations
'
' > Greater Than
' < Less Than
' >= Greater Than Or Equal To
' <= Less Than Or Equal To
' = Equal to

x = 0

if x = 0 then print "Zero"

' --------------------------
' if/then/else
if x = 0 then
print "Zero"
else
print "Nonzero"
end if

' --------------------------
' not
if x then
print "x has a value."
end if
if not(x) then
print "x has no value."
end if

' --------------------------
' if .. end if
if x = 0 then
print "Zero"
goto [surprise]
end if
wait

if x = 0 then goto [surprise]
print "No surprise."
wait

[surprise]
print "Surprise!"
wait

' --------------------------
' case numeric
num = 3

select case num
case 1
print "one"

case 2
print "two"

case 3
print "three"

case else
print "other number"

end select

' --------------------------
' case character
var$="blue"

select case var$

case "red"
print "red"

case "green"
print "green"

case else
print "color unknown"

end select

  

You may also check:How to resolve the algorithm Sorting algorithms/Counting sort step by step in the IS-BASIC programming language
You may also check:How to resolve the algorithm Word wrap step by step in the Tailspin programming language
You may also check:How to resolve the algorithm Abstract type step by step in the Logtalk programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Jinja programming language