Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Else Statements!!! (http://www.chiefdelphi.com/forums/showthread.php?t=15529)

Adam Shapiro 18-12-2002 22:32

Else Statements!!!
 
Who else is annoyed about working with a language that doesn't have an else statement? I know that I, for one, can not stand having to write if statements that jump over other if statements that jump over gotos... Your thoughts?

rbayer 18-12-2002 22:35

Equivalent of else:

if <<something>> then trueLabel
<<stuff for else>>
goto endIfBlock

trueLabel:
<<trueStuff>>

endIfBlock:


It's really not that bad once you get used to it.

Joe Matt 18-12-2002 22:36

I'm learning it now, so yeah, it sucks. That's what AppleScript is for. :)

Adam Shapiro 18-12-2002 22:44

I agree that it isn't that bad after a while but still, it is quite annoying. Too many goto's. I would much rather work in just about any other language where I could use else statements, not to mention code blocks (C++, etc.). On the other hand, being so simple makes PBasic extrememly easy to pick up (took me about 2 days to get it down really well...).

Jnadke 19-12-2002 10:34

Hehe... you think this is bad? Try working on Assembly.

Matt Leese 19-12-2002 13:31

Quote:

Originally posted by Jnadke
Hehe... you think this is bad? Try working on Assembly.
Some of us like assembly. Then again, I suppose x86 assembly is pretty bad (4 registers and a horribly complex addressing mode) as is ARM (where you have to manually stall the pipeline as it doesn't do branch prediction).

Matt

Adam Shapiro 19-12-2002 15:48

I guess that's true...I once took an attempt at assembly and gave up after only a few minutes. Maybe it just wasn't meant to be...

Mongoose 21-12-2002 16:59

I find it annoying that you skip over the next block of code if a condition is true. It's just not logical. You get used to it. If you really insist, there is a way for a plain old if-statement, though:

if(condition) then doStuff:
goto skipStuff
doStuff:
' Your code here
skipStuff:

Since it's winter break, I'm learning assembly right now for my TI83+ (z80 processor). It's not all that bad.

Adam Shapiro 21-12-2002 23:13

How are you learning it? I'm guessing online tutorials (that's pretty much how I learned all the programming I know...). I think I'll probably take another crack at it during vacation and see what happens...wish me luck...

Lloyd Burns 22-12-2002 01:27

The basis for this jump is the machine that was in the first BASIC Stamp - the PIC from Microchip. Its only decision is a flag-test followed by a skip over the next instruction to the instruction after that. It has one register you can load, and it is busy ! The on-board RAM is set up in 'files' : 8 bit locations you assembler allows you to name, and they do get cramped.

[compare Alpha to Beta]
MOVF,W Beta 'move contents of 'file' (ram location) I call beta to W (work reg)
SUBWF,W ALPHA 'subtract W contents from 'file' I call Alpha
BTFSS CARRY ' Bit Test flag(here, a carry), Skip if carry is set
GOTO CARCLEAR ' This instruction skipped if carry was set, else jump occurs
MOV..... ' IT was set, Alpha >= Beta
......
CARCLEAR ...... 'It wasn't zero, come to this label Beta > Alpha

-or-

[do..while_not_zero loop]
MOVLW .5 'move 5 (dec) into the tiny 'working register' (W)
MOVWF Index 'move contents of W into a 'file' register I've called Index
GUTS (label)
do something
DECFSZ Index 'decrement Index, skip if dec'ing caused the zero flag to set
GOTO GUTS loops back to guts if not zero
.....

If you don't like jumping if true in PBASIC, you can alway test for a condition you know will *not* occur. You can use preprocessors, high level languages, and other artifice to get you away from the silicon (and don't the people love to), or you can have fun playing in the sand . :)


All times are GMT -5. The time now is 00:59.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi