Freigeben über


Small Basic - Spaghetti Code

What is Spaghetti Code?

As Yan mentioned, an old friend once said, "Spaghetti is best served on your plate, not in your code."

Take a look at this program:

' Shows you how Goto statements can create spaghetti code

Goto Line4

Line1:

    TextWindow.Write("spaghetti ")

    Goto Line6

Line2:

    TextWindow.Write("an ")

    Goto Line5

Line3:

    TextWindow.Write("of ")

    Goto Line1

Line4:

    TextWindow.Write("This is ")

    Goto Line2

Line5:

    TextWindow.Write("example ")

    Goto Line3

Line6:

    TextWindow.WriteLine("code.")

 

Output:

This is an example of spaghetti code.

 

As you can see, it’s hard to track the flow of this program. Like spaghetti, this program’s a tangled mess! Try to trace through the program to see how it works!

 

Do you have any questions? Ask us! We're full of answers and other fine things!

Head to the Small Basic forum to get the most answers to your questions: 

https://social.msdn.microsoft.com/Forums/en-US/smallbasic/threads/   

And go to https://blogs.msdn.com/SmallBasic to download Small Basic and learn all about it!

 

Small and Basically yours,

   - Ninja Ed & Majed Marji

   

================

See Also:

Comments