If Then Statements And Goto Command


After compiling all those things that we just did, we finally get to the even juicier part: If then! After this post, you should be able to create simple yet useful programs for yourselves. Here is my simple program:

1 a=0

2 print “You have:”,a

3 print “Hit or stand?”

4 input g

5 if g==”y” then goto 8

6 print “You stand with:”,a

7 end

8 print “Here we go…”

9 b=0

10 b=rnd(6)

11 if b!=0 then goto 14

12 print “Snakeeye! You have $0!”

13 end

14 a=a+50

15 goto 2

There are many lines (15), but none of them uses more than:

-Print

-Input

-Variables

-Random

-End

-Goto

-!=

-==

-=

-etc.

Because I haven’t taught you all of this, I’m here to help!

!= means not equal to, so if <variable>!=3, pretty much means if something is not equal to 3, then blah blah blah.

== means equal to. Pretty much the same as above except for equal

end means pretty much end the program.

If Then:

If then statements mean that if something happens, then do something- simple right? Here is a real life scenario:

if it is nighttime, then turn on the nightlight

Same thing with the program!:

If x!=3 then <action>

<action> could mean print, a mathematical problem, or most frequently, a goto, which is told below.

Goto:

Gotos mean repeats, or loops. Instead of saying:

1 print “5”

2 print “4”

3 print “3”

4 print “2”

5 print “1”

You could say:

1 a=5

2 print ,a,

3 a=a-1

4 if a > 0 then goto 2

5 end

although the above might seem easier, some more complicated things may not be that way, for example, in Minecraft, the developer simply cannot program every single brick, he/she could simply duplicate the brick’s programming.

Yep, another big mouthful (Sorry!?)

Experiencedsitemaker

Advertisements

The Debate Form

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s