NASutils Knowledge BaseUnofficialPolski

BASIC · lesson 7 of 30 · Decisions and loops · bonusDecide with if

if, elsif, else and endif choose one of several blocks. The check for a wrong number comes first.

Programming on the NAS › BASIC in 30 lessons

07-if.yab Download 07-if.yab

input "Disk temperature in C: " temp

if temp < 0 or temp > 100 then
  print "Type a number from 0 to 100"
elsif temp >= 55 then
  print "Too hot: check the fans"
elsif temp >= 45 then
  print "Warm: look again in an hour"
else
  print "Fine"
endif

Terminal

$ yabasic 07-if.yab
Disk temperature in C: 38
Fine
$ yabasic 07-if.yab
Disk temperature in C: 58
Too hot: check the fans
$ yabasic 07-if.yab
Disk temperature in C: 900
Type a number from 0 to 100

Exercise

Ask for the free space in percent and answer fine, low or full.