The following warnings occurred:
Warning [2] Undefined array key 0 - Line: 1677 - File: showthread.php PHP 8.2.31 (Linux)
File Line Function
/inc/class_error.php 157 errorHandler->error
/showthread.php 1677 errorHandler->error_callback
/showthread.php 916 buildtree




Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UBYTE/FOR loop issue?
#2
Well, this time it's not a bug, but a expected behaviour due to Ubyte overflow.
This question has already been answered here and previously here.

The problem comes because FOR a = 1 to 255 means "repeat until a > 255", since a is byte, that variable won't ever reach 256!.
This also happens in C and in other BASIC compilers. If you strinctly want to loop from 1 to 255 using uByte, use DO UNTIL looping statement:
Code:
Dim a as Ubyte = 0 Do LET a = a + 1 PRINT a Loop Until a = 255
Note, must use another PRINT before "Do" if you also want to print 0 (0 .. 255 => 256 times and so on.)
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)