Goto Function?
-
Just started to dabble into this today, so brand new to this coding, but it's pretty similar to BASIC. That being said, what is the command for GOTO? I'm trying to start off a simple, trying to make five random cards appear from a deck of cards. I'm trying to have it pick another card if it's already been picked, but I'm unable to send use the 'goto' command to get back a few lines on code to try again. Didn't see anything in the tutorials. What is used in place of goto?
-
Try using functions instead
-
Hi, as there is no use of line numbers other than a reference for error checking so GOTO is very much redundant.
I will miss:
10 PRINT "DIXONS STAFF ARE RUBBISH"
20 GOTO 10Now we use user functions.
My programs for example generally look something like this:
cards = [.heart = [], .diamond = [], .club = [], .spade = [] ] player = 0 computer = 0 setup() // jump to a routine called setup loop // the main loop clear() checkInput() // my own function to check the controls updateScreen() // my own function to draw everything to the screen update() // the system command to update the screen display repeat function checkInput() return void function updateScreen() return void function setup() // set up my main variables, load images and basically dump all the config stuff here //load graphics etc. //load sounds //assign structures and arrays return void // void is nothing
In the old BASIC days, and specifically with BBC BASIC you would know this as procedural programming - each subroutine being a PROC routine.
This is exactly the same same as user functions and basically an advanced version of GOSUB. The difference is that you can pass information to a function and return results back at the same time - the same as DEF FN in some versions of BASIC but all combined into one.
Once you have gone procedural / user functions, you'll never look back.
Sorry, went on longer than expected!
-
Useful info. We'll have to go the function route... :) Thanks!
-
goto in modern programming languages is no longer a good practise and can procude really bad results if missused, so better to not have it so poeople new to programming and starting with fuze will not learn that, ok it's sad not having this historyc basic feature, but teaching newcomers proper modern programming is more important
-
Functions replace Gosub, I'd say that the loop and repeat keywords replace Goto.
so instead of
10 PRINT "Hey That's Great"
20 GOTO 10it's
loop
print ("Hey That's Great\n")
repeatAlthough I get mixed up with qbasic having that be do loop (or while wend in even earlier microsoft basics) instead of loop repeat. Not sure why that had to be different.
-
I have the same sentiment coming from that same school with QBasic.. I think that in today's society to relate yourself to being too much similar to BASIC is a henderance to C/C++ snobs who won't hear anything of it and were "lucky" enough to be born with a silver compiler in their tongue and take 4 times as many lines just to print "Hello World" while loading their INCLUDE libraries...
So BASIC has a stigma and ANY new language must relate itself more steadfastly to the likes of Python and Javascript perhaps to gain the attention that Fuse definately has ever AS it IS in fact, a TAD closer to BASIC than most would like to admit.
-
On that note, I invite ANY old QBASIC "fool" to go to qb64.org and get a free copy of the 64-bit compiler built ON QBASIC and yet boasting rich HI-DEF GRAPHICS AND ELASTIC WINDOW-ABLE MODES, FULL MP3 SOUND SUPPORT WITH A FEW LINES ONLY... also loads NORMAL JPG images as well!! more intuitive mouse control as well. It's FAR more advanced and yet LOOKS exactly the same.. it is a full compiler so you WILL compile EVERY time before running.. but it is in fact written in C/C++ to begin with so.. there's THAT. LMAO.
-
I think Freebasic is a good new version of basic. It doesn't get as much attention though.
-
Was just reminded of this
-
HAHAHHAA!! That's awesome.