If, Then, Else problems

Blitz3D Forums/Blitz3D Beginners Area/If, Then, Else problems

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

you don't have any code for if billy = 20 and sam = 15 !!

It will help to see what's going on if you "indent"
your code, ie line up the ifs and end-ifs so you can
see which end-if corresponds with which if :-

If billy = 10 
   If sam = 5 
      Text 0,130, "Sam and billy are 15 in total" 
   Else 
      If billy = 20 
         If sam = 10 
            Text 0,130, "same and billy are 30 in total" 
         Else 
            If billy = 50 
               If sam = 50 
                  Text 0,130, "sam and billy are 100 in total" 
               EndIf 
            EndIf 
         EndIf 
      EndIf 
   EndIf 
EndIf


This might look better if you use "AND" statements
instead of all those IFs :-

If billy = 10 and sam = 5 
   Text 0,130, "Sam and billy are 15 in total" 
Else 
   If billy = 20 and sam = 10 
      Text 0,130, "same and billy are 30 in total" 
   Else 
      If billy = 50 and sam = 50 
         Text 0,130, "sam and billy are 100 in total" 
      EndIf 
   EndIf 
EndIf



You should have an extra "else" in to cater for any
situations which you have not explicitly checked
for in your "IF" statements :-

If billy = 10 and sam = 5 
      Text 0,130, "Sam and billy are 15 in total" 
Else 
   If billy = 20 and sam = 10 
      Text 0,130, "sam and billy are 30 in total" 
   Else 
      If billy = 50 and sam = 50 
         Text 0,130, "sam and billy are 100 in total"
      else
         Text 0,130, "Something else !!"
      EndIf 
   EndIf 
EndIf



You might want to consider what you want to happen if
billy = 8 and sam = 7 ......
In the above program, it will say "something else"
when you might expect it to say "Sam and billy are 15 in total".
It's easy to forget that the computer will print out
everything you tell it to without checking if it's
correct or not !


If billy + sam = 15 
      Text 0,130, "Sam and billy are 15 in total" 
Else 
   If billy + sam = 30 
      Text 0,130, "sam and billy are 30 in total" 
   Else 
      If billy + sam = 100
         Text 0,130, "sam and billy are 100 in total"
      else
         Text 0,130, "Something else !!"
      EndIf 
   EndIf 
EndIf



When you've mastered this, have a look at the
"case" and "select" commands (see the help text for
info on these)