PRB: For Loop w/ Integer Counter & Increment <=.5 Causes HangLast reviewed: June 21, 1995Article ID: Q87769 |
This information applies to the following Microsoft Basic products:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0- Microsoft Visual Basic programming system for Windows, version 1.0 - Microsoft QuickBasic for MS-DOS, versions 4.0, 4.0b, and 4.5 - Microsoft Basic Professional Development System (PDS) for MS-DOS, versions 7.0 and 7.1
SYMPTOMSIf you write a FOR loop with an INTEGER or LONG variable as the FOR loop counter and use a floating point value less than or equal to 0.5 as the FOR loop increment, the loop never terminates. This causes the computer to hang (stop responding to input).
CAUSEAll Basic programs convert floating point values less than 0.5 to the integer value 0.
RESOLUTIONTo stop a program that is executing in this type of an endless loop, press CTRL+BREAK.
STATUSThis behavior is by design. In other words, this is not a problem with the FOR statement; this is the way Basic is designed to operate.
MORE INFORMATION
Steps to Reproduce Behavior in Visual Basic for Windows
To change this example program so that the loop terminates, change the type of the counter variable from LONG to SINGLE (change j& to j!).
|
Additional reference words: 1.00 2.00 4.00 4.00b 4.50 7.00 7.10 b_quickbas
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |