| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Compiler quirk? |
Here is a conundrum I just ran across, where the PB32 compiler isn't
compiling quite as I would expect. Consider this code...
FOR test% = 1 TO 3
IF test% = 3 THEN test% = -333: test% = 999
PRINT test%
NEXT test%
The quirk is in the colon that separates the IF statement from
the LET statement (test% = 999). I would expect the compiler to
treat this code as equivalent to this...
FOR test% = 1 TO 3
IF test% = 3 THEN test% = -333
test% = 999
PRINT test%
NEXT test%
But, instead, the compiler compiles it as the equivalent of this...
FOR test% = 1 TO 3
IF test% = 3 THEN
test% = -333
test% = 999
END IF
PRINT test%
NEXT test%
Am I just all wet, or am I onto something here? How do others think
the compiler should behave in this instance? Inquiring minds want to
know.
Brian M.
* SLMR 2.1a * MAXLIB For PB v1.2 - Access arrays and files in EMS/XMS!
--- WILDMAIL!/WC v4.12
---------------
** A related thread FOLLOWS this message.
FIDO MESSAGE AREA==> TOPIC: 214 POWER BASIC Ref: D2QK0499 Date: 02/21/96
From: KURT KUZBA Time: 04:08pm
\/To: BRIAN MCLAUGHLIN (Read 3 times)
Subj: R: Compiler quirk?
BM> Here is a conundrum I just ran across, where the PB32
BM> compiler isn't compiling quite as I would expect. Consider
BM> this code...
BM> FOR test% = 1 TO 3
BM> IF test% = 3 THEN test% = -333: test% = 999
BM> PRINT test%
BM> NEXT test%
BM> I would expect
BM> FOR test% = 1 TO 3
BM> IF test% = 3 THEN test% = -333
BM> test% = 999
BM> PRINT test%
BM> NEXT test%
BM> Am I just all wet, or am I onto something here?
bm>........................................................
You are onto code block formatting.
FOR test% = 1 TO 3
IF test% = 3 THEN
test% = -333: test% = 999
END IF
'_|_|_| IF test% = 3 THEN test% = -333: test% = 999
'_|_|_| This is the equivalent statement in single line form
PRINT test%
NEXT
For convenience, where the code is not excessive of a line,
the END IF is implied at the end of the line, and you do not need
to create three lines of code where a single line would serve.
---
> ] * Origin: Com-Dat BBS - Hillsboro, OR. HST DS (1:105/314.0)* Origin: AD Message BBS/10th Year Online! (703)241-1826 (1:109/611@FIDONET) |
|
| SOURCE: echomail via exec-pc | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.