break testing printouts ( For / Next one loop )

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
ppf
Posts: 45
Joined: Oct 10, 2017 6:41

break testing printouts ( For / Next one loop )

Postby ppf » Jun 09, 2019 10:46

Hi,
one small tip; founded this tricky usefull for shorten create&debug process; in case of 'For-Next' very long loop (of some action).
Originally used one more cycle 'Do-Loop' inside of 'For-Next' to detect keypresses and break testing printouts,
whatever you want to see if it's created correctly.
But why to have two loops, if you have one in running ? ;)

Code: Select all

for i as integer=1 to 1000000
 'generate/iterate something or so
 'print its contents on screen

 'and if all is Ok - break it
 if inkey<>"" then exit for               'press any key
  rem if inkey=chr(27) then exit for      'press Esc
  rem if inkey="q" then exit for         'press "q"
next
  sleep
  end
'and build your next code...
badidea
Posts: 1542
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: break testing printouts ( For / Next one loop )

Postby badidea » Jun 09, 2019 13:54

Be aware that checking inkey for each iteration might slow your loop down. For debugging probably not a problem.
The alternative in multikey (a bit faster), but there seems to be a bug (linux only?). Without the first print statement the program freezes on pressing escape here:

Code: Select all

print "Start" 'delete this line for test
dim as double t = timer
for i as integer = 1 to 10000000 * 10
   if multikey(1) then
      print "Aborted by <escape> key"
      exit for
   end if
next
print timer-t; " seconds"
while inkey = "": wend
print "End"

Return to “Tips and Tricks”

Who is online

Users browsing this forum: MSN [Bot] and 18 guests