[pascal]For I:= 0 to –1 do beep();[/pascal]
How many time beep() will be preformed?
[pascal]For I:= 0 to –1 do beep();[/pascal]
How many time beep() will be preformed?
[size=9px]BEGIN GEEK CODE BLOCK
<br />d s-- : a24 GB GCS GTW GE C++ P L+ W++ N+ K- w++++ M- PS+ PE+ Y- t+ 5+++ X+ R*
<br />tv b+ DI++ D+ e++ h+ G-
<br />END GEEK CODE BLOCK[/size]
<br />Create your own GeekCode block at: <a href="">...</a>
:lol:
what kind of test is that? :lol:
Will: "Before you learn how to cook a fish you must first learn how to catch a fish." coolest
I really don't understand if this would be a trick or something... :? :lol:
<center>
<br />Federico "FNX" Nisoli
<br />Lead Programmer - FNX Games
<br />http://www.fnxgames.com
<br /><img src="http://www.fnxgames.com/imgs/banners/fnxban.gif">
<br /></center>
In the former version of my script language the answer would have been 1
Peregrinus, expectavi pedes meos in cymbalis
Nullus norvegicorum sole urinat
0. Because once you click compile, Delphi, and even Freepascal, would beat you over the head with a very large hammer.
probably 0 times, unless the overflow checking is OFF, in that case it will go around and beep 4294967295 times.
This is my game project - Top Down City:
http://www.pascalgamedevelopment.com...y-Topic-Reboot
My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
http://www.pascalgamedevelopment.com...source+manager
zero times, surely!?
I routinely use this sort of code:
And if high(GameObjects) returns -1, as it does when the program is first run, it just skips the for loop.Code:For I := 0 to high(GameObjects) do something;
Well technically if there is a thunderstorm outside and your computer is right beside the window and a bolt of lightning hits your computer case and zaps the guts of it right as you hit F9, it could possibly end up doing a single beep as it powers down it's newly fried circuits.
The reason I asked this is because I had a similar code to that (only difference was that -1 was a var) that compiled and ran as 90% expected (if the var was –1 it didn’t enter the loop) using Delphi6.
Few weeks ago I needed to add a few features to that application and I decided to do it with Delphi2006. The new futures I added worked fine but accompanied with it was a strange new bug..
Long story short, after several hours of debugging I found the problem with the for loop. It wasthe exact same code that worked fine in Delphi6, but in Delphi2006 I had to add an If statement before the loop!
It’s the first time I encountered this kind of behavior with for loops.. but hey, I’ve seen worse :?
[size=9px]BEGIN GEEK CODE BLOCK
<br />d s-- : a24 GB GCS GTW GE C++ P L+ W++ N+ K- w++++ M- PS+ PE+ Y- t+ 5+++ X+ R*
<br />tv b+ DI++ D+ e++ h+ G-
<br />END GEEK CODE BLOCK[/size]
<br />Create your own GeekCode block at: <a href="">...</a>
The most common case I've seen for needing an if statement before a for loop was when you are accessing object classes within that loop that may not have it's first element created so you'll get a memory error because the class was not pointing to memory that was allocated.
Other than that I don't see much reason to use an if statement as I've come to understand the language. Maybe avoid triggering an over anxious debugger?
Bookmarks