|
I seem to remember (it's been a while ) that Cobol didn't have a For loop.
In fact all loops used Perform... constructs.
There was a Perform Varying - which is like a For
In fact there wasn't a While.. or Do.. either - it was all
Perform Until... or Perform ... Until.
Take a chill pill, Daddy-o
.\\axxx
(That's an 'M')
|
|
|
|
|
maxxx# wrote: the programmer assumed
See, there's the problem.
But if the spec says to do that, then it's OK and you can blame it on the monkey who wrote the spec.
Ideally, the programmer would ask for clarification (in an email), and then take a break awaiting a response, however long that takes.
But this is clearly a case in which while is the proper construct.
Oh...
maxxx# wrote: why would you want to select to print zero copies
To just save the file on disk. I seem to recall this in a system I had to support a bunch of years ago. The PRINT program would generate a report file, which it could then print. Oh, right, it was a VAX/VMS system, so the file got spooled to a print queue, not sent to the printer directly. As I recall, saying 0 for copies, or 0 for paper type would indicate that you didn't want to print it.
Bonus: Even though VAX/VMS allows a print job to specify the number of copies as 1 to 255, this PRINT program only allowed up to 20 . One of the users needed 80 copies of a particular report, so she ran it four times, each time having to get the input just right. Eventually I realized what she was doing. Because we had the source code (VAX BASIC ) I was able to change the program to allow the full 255 copies.
|
|
|
|
|
PIEBALDconsult wrote: you can blame it on the monkey who wrote the spec.
How did you know it was the monkey?
PIEBALDconsult wrote: Ideally, the programmer would ask for clarification (in an email), and then take a break awaiting a response, however long that takes.
This was in the days before email! Indeed, in the days before taking breaks!
PIEBALDconsult wrote:
To just save the file on disk. I seem to recall this in a system I had to support a bunch of years ago. The PRINT program would generate a report file, which it could then print. Oh, right, it was a VAX/VMS system, so the file got spooled to a print queue, not sent to the printer directly. As I recall, saying 0 for copies, or 0 for paper type would indicate that you didn't want to print it.
That's just a case of extremely poor UI - why not have a Save and Save and Print option - or something more obvious to show theuser what is happening - selecting zero copies isn't really intuitive to save a file!
Oh - and on the system this was written on (TI 990) you could select the number of copies in the spooler - so in fact there was no need for a loop at all!
Take a chill pill, Daddy-o
.\\axxx
(That's an 'M')
|
|
|
|
|
maxxx# wrote: extremely poor UI
Yeah, well the system was developed in Roswell, New Mexico, so all bets are off.
|
|
|
|
|
PIEBALDconsult wrote: Yeah, well the system was developed in Roswell, New Mexico, so all bets are off
So it was an UFO GUI?
Take a chill pill, Daddy-o
.\\axxx
(That's an 'M')
|
|
|
|
|
personally i dont think you're missing much by not having Guiness, but why not just do while copies > 0 no other validation needed, except to ensure the value entered was a number.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I use do...while on occasion. It's actually a useful loop that ensures code is performed at least once. Certainly you can always do the same loop using a standard while loop, but often it increases readability and comprehension.
|
|
|
|
|
SomeGuyThatIsMe wrote: I have yet to find a use for a do..while loop, and continue to wonder what you really need them for.
That's a bit of a horror right there.
Faith is a fine invention
For gentlemen who see;
But microscopes are prudent
In an emergency!
-Emily Dickinson
|
|
|
|
|
i've just found other loops more usefull, i understand what they're for, just never found a situtation nwhere they're the best fit, in the above i would have use while copies > 0, and not had to check what the value of copies was as long as i checked the user input to make sure its a number, depending on how they were allowed to enter it. i've known people who have been doing thise for 15 - 20+ years and they have to go out of their way to use one. maybe it got ingrained in my head at some point to not think using post checks, and to always use prechecks..i dont know.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I can probably count on one hand the number of times I have had to use do/while , and probably on all fingers and toes the number of times I used just a while (which correlates almost exactly to the number of times I have had to write a TCP server, and then it still has a goto or 2!).
|
|
|
|
|
|
Yeah - I once had a user backing up their data, every day, to floppy for six months. Then they had a crash and needed to restore and the restore didn't work. I had to go over to see what the issue was...
I Start restore
"Insert Disk 1"
I ask for the first floppy, and insert it...
"Disk 20 of 20: Please insert disk 1 of 20"
I ask for the first floppy..
"Oh, there's only one." says the user.
"But this is disk 20" quoth I.
<snip -="" long="" and="" confused="" conversation="" ensued="">
"So," i calmly stated "when the backup program said 'Insert Disk 2 then press Enter to continue.' you pressed Enter. Then when the message **Warning disk will be Formatted - All data will be lost**', you just pressed Enter again?"
"Yes." replied the user, in a tone which suggested that only a fool would do anthing else. "and the same for disk 3, and 4 ... We thought it was clever to fit all that data onto one disk! Isn't that what formatting means?"
I suppose I should have realised they weren't the smartest bunch on the planet when, in previous years, they had folded an old 5 1/4" diskette in half to send through the post (and stapled a with-compliments slip to it) and seemed surprised that I couldn't read it!
Take a chill pill, Daddy-o
.\\axxx
(That's an 'M')
|
|
|
|
|
Ah, tech support just isn't as much fun as it used to be.
|
|
|
|
|
Nope - but we still use the "Have you tried switching it off and back on again" trick
Take a chill pill, Daddy-o
.\\axxx
(That's an 'M')
|
|
|
|
|
you mean they didn't want 4294967294 copies??? (till it reached zero again)
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
I used to work with a guy who was clever enough to write this:
For i = 1 To 5
If i = 1 Then
...
Else If i = 2 Then
...
Else If i = 3 Then
...
Else If i = 4 Then
...
Else If i = 5 Then
...
End If
Next i
I guess the coder wanted to do something "in five steps". He certainly does.
We don't work together anymore
|
|
|
|
|
Maybe there is a i++ in some states in the if blocks to skip steps?
James Simpson
Web Developer
imebgo@hotmail.com
P S - This is what part of the alphabet would look like if Q and R were eliminated Mitch Hedberg
|
|
|
|
|
Nope, the i did nothing else
|
|
|
|
|
How else would he know what step he was at? Now he can simply refer to i in the debugger!
|
|
|
|
|
While a select-case statement would probably be better than the cascaded if/else-if, the illustrated construct may not be unreasonable in certain cases where it is expected that the inside of the loop will be pulled out into a separate routine for use as a state machine. Having the code within a for-next loop may be handy during development while the code is being perfected, even if the final construct will be something else.
To be sure, when running on a PC it's often easier to use threads rather than state machines, but state machines can often have a much lower 'footprint'. If an application will require hundreds or thousands of objects each with a multi-way state machine, and all have to be operable concurrently, a select-case state machine may be a reasonable approach. Delegates should be considered as well, since they have some advantages (but also some disadvantages), but state machines are reasonable in simple cases.
|
|
|
|
|
Wow...
Just wow...
Where in the original WTF did it mention a problem that would require State Machines or Threads to solve?
You've created a mountain out of a grain of dirt.
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
Tristan Rhodes wrote: Where in the original WTF did it mention a problem that would require State Machines or Threads to solve?
My point was that there are circumstances where code like that illustrated may be useful. While it is true that there was nothing to indicate that such circumstances applied here, I would not wish to condemn code without knowing that such circumstances did not apply.
BTW, another circumstance where such code may be useful is in cases where the loop will evolve into something like:
for i=1 to 5
.. do some stuff in every case
if i=1 then
.. handle first case
else if i=2 then
.. handle second case
... etc
end if
.. do some more stuff in every case
In many circumstances, that style of code could be handled better by putting the different parts into subroutines and just calling them:
everycase_prep()
.. handle first case
everycase_cleanup()
everycase_prep()
.. handle second case
everycase_cleanup()
In some cases, however, the prep and cleanup would need to share many local variables, thus requiring either long parameter lists or awkward class constructs.
|
|
|
|
|
Take brain – Turn off brain – Start coding.
yvind Bratland wrote: We don't work together anymore
Surprise! Surprise!
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Of course you two don't work together anymore.
This guy's a visionaire! You simply cannot understand the superior maths under this construction.
Kazz
"Users are there to click on things, not think. Let the archs do the damn thinking."
|
|
|
|
|
yvind Bratland wrote: We don't work together anymore
I bet that's a good thing
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|