Jump to content
Science Forums

Recommended Posts

Posted

New Path - finding Algorithm?

 

I am more on traditional algorithms and their block - schema

I found very useful an never ending loop of QBasic of the type

 

for i = 0 to 1

i = 0

 

 

{ your program stuff }

 

 

x$ = inkey$

if x$ = "q" then i = 1

next

 

I also wander

is the hard disk bringing all its data into the huge memory of the pc

continuously - frequently

or still working step by step, fragments after fragments!

Anyway, money matter!

 

Where can I find an algol help file suitable to windows' modern windows;

not only to cmd windows' windows! Sorry to ask at this time of such marvel cybernetic era!

 

 

Posted

[Moderator's Note: this thread was split off from a discussion on path finding as it was not relevant to that topic.]

 

The problem with infinite loops is that they chew up enormous amounts of useful processor time, and in general you should never ever write such code.

 

Operating systems all now provide access to "sleep" call which tells the operating system to put the process to sleep for some period of time and then have it continue processing. When these functions were originally developed, they were normally put into loops like the one you have above:

while (true) do
   /* do your processing */
   sleep(10) /* sleep ten seconds */
end while

Now however the more general approach is to define a call back function and actually have the program create a separate thread that deals with the processing so that the program itself can proceed with other processing rather than having the whole program have to come to a halt:

function do_my_processing()
   /* do your processing */
end function
 
function main()
   /* do startup processing*/
  fork(do_my_processing, 10)     /* call the function do_my_processing every 10 seconds */
  /* do other stuff */
end function

As to your second question, the hardware on the disks these days do a tremendous amount of pre-fetching (predicting what you want next) and caching (keeping stuff around after you've looked at or updated it) in fast RAM on the controller board. As a result there has been less of this done by actual application programs (database engines used to do a lot of this), but it is still a standard feature of most operating systems too (that's why you should never, ever unplug a Mac or a *nix system). 

 

Back when the size of RAM was increasing faster than disk sizes, there was some discussion about a future in which the RAM was actually bigger than the disk, so you'd definitely bring the whole thing into memory. That of course has never happened yet, as we seem to not only increase disk sizes and a rapid pace, but find more stuff to save.

 

 

It is a very sad thing that nowadays there is so little useless information, :phones:

Buffy

Posted

But I use infinite loops quite often, but more to compute something and exit when it it is good enough, so a infinite loop with an exit condition just like a while loop

 

Oh, I'm not saying "always" just "in general": In cases like waiting for input it's a really really bad thing.

 

But yes, even I write code like this:

 

 

while (true)
    /* do some stuff that you need to do before seeing if you're done */
    if (done_looping())
        break;
    /* do some more stuff that you need to do before looping again like incrementing counters */
end while

 

HOWEVER, any time you have a "while(true)" you have bug bait, and I always try to come up with some fail-safe test for the "true" in these statements because this is a good way to lock up your machine if you don't have the debugger running.

 

 

Civilization is the process of reducing the infinite to the finite, :phones:

Buffy

  • 6 months later...
Posted

HOWEVER, any time you have a "while(true)" you have bug bait, and I always try to come up with some fail-safe test for the "true" in these statements because this is a good way to lock up your machine if you don't have the debugger running.

 

 

So true Buffy. The inkey$ command actually reads the first character in the keyboard buffer so the main problem with the type of code in the OP is that the test is only for a lowercase 'q' and you will not be able to exit the loop if the caps lock key is on. 

 

 

 

 

Posted

I am more on traditional algorithms and their block - schema

I found very useful an never ending loop of QBasic of the type

 

for i = 0 to 1

i = 0

 

{ your program stuff }

 

x$ = inkey$

if x$ = "q" then i = 1

next

I wouldn’t call this a never-ending loop, because it ends when “q” is inputted.

 

I think a better way to code this in QBasic is

do
{ your program stuff }
x$=inkey$ 
loop until x$=”q”
Posted

Where can I find an algol help file suitable to windows' modern windows;

not only to cmd windows' windows! Sorry to ask at this time of such marvel cybernetic era!

 

If you use something like Visual basic (or any MS Visual Studio language) you can create a new window/form and populate it with buttons and data elements via the screen editor.

 

Very simplistically you can create two command buttons on your form, one called 'RUN' and the other called 'Quit' and add your own processing code under the RUNbutton.click property and then add 'thisform.release' to the Quitbutton.click property.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...