Various Small Tips and Tricks

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Various Small Tips and Tricks

Post by badidea »

How about a topic for various small "Tips and Tricks"? (If a bad idea form badidea, this topic can be ignored or deleted)

Small things that can prevent bugs or are neat tricks do to something. But where a whole new topic seems a bit much.
Things that might a obvious for some, things you learned to do over time, or are in the manual, but you never noticed.

I start with one. Don't do this (as I did a few minutes ago):

Code: Select all

dim as integer i
'code
for i = 0 to 9
	print i
	'code
next
Because you might end up with this:

Code: Select all

dim as integer i
for i = 0 to 9
	print i
	'code
	for i = 0 to 4
		'code
		print i;
	next
	print
next
Which makes your code hang or give unexpected results.
Instead use:

Code: Select all

for i as integer = 0 to 9
	print i
	'code
	for i as integer = 0 to 4
		'code
		print i;
	next
	print
next
Or use:

Code: Select all

dim as integer iBox, iCorner
for iBox = 0 to 9
	print iBox
	'code
	for iCorner = 0 to 3
		'code
		print iCorner;
	next
	print
next
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Various Small Tips and Tricks

Post by MrSwiss »

badidea wrote:How about a topic for various small "Tips and Tricks"?
From my point of view: things like that, can be posted in: "Beginners".
(Since it is only interesting, for Beginners.)
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Various Small Tips and Tricks

Post by grindstone »

The problem is not so much to write and to post those snippets, but to find them. An unsorted assemblage is nearly useless.
Post Reply