Re: If endif loop with 'OR'
Quote:
If ( ax < bx) Or (bx - ax >= 180) Then
Gosub cwise
Endif
this will work if your math is correct
1 Attachment(s)
Re: If endif loop with 'OR'
Hi Richard,
Thanks for your reply.
I forgot to say that I am using Oshonsoft.
See attached result image.
C
Re: If endif loop with 'OR'
this compiles just fine from mcs
Code:
poscnt var word
azimval var word
time var byte
main:
if (poscnt<azimval) or (azimval-poscnt >= 1800) then
gosub cwise
time=0
endif
goto main
end
cwise:
return
take up the issue with Oshonsoft.
Re: If endif loop with 'OR'
Hi Richard,
There are a few glitches in Oshonsoft, and queries are usually not answered, so I just work with what's there. I tried a few combinations of OR IF THEN ELSE ETC, but no compile.
If I say the answer to my question is:
If poscnt < azimval Then
If azimval - poscnt >= 180 Then
Gosub ccwise
counter = 0
Else
Gosub cwise
counter = 0
Endif
Endif
You may notice that I had asked the wrong question:rolleyes: I have more difficulty than I should have with lines like: (If azimval - poscnt >= 180 Then) so things take 50 times as long as they should. Anyway It's working now.
Thanks and HAPPY NEW YEAR.
C.
Re: If endif loop with 'OR'
There’s nothing wrong with what you’re doing with the IF/THEN statements
so long as you follow it, the compiled code is similar, and possiblly even worse.
Code:
if (battery=charged) && (lightbulb != blown) then ‘ AND
bulb will light
endif
if (battery = flat) || (lightbulb = blown) then ‘ OR
bulb will not light
endif
Re: If endif loop with 'OR'
Hi Art,
As I've been monolingual with basic since the early 80s, your reply is another puzzle, but thanks. I'll stick to IF/THEN.
C.
Re: If endif loop with 'OR'
Hi,
Code:
if (poscnt<azimval) or (azimval-poscnt >= 1800) then
I just would had written ...
Code:
if (poscnt<azimval) or ((azimval-poscnt) >= 1800) then
to be sure of what happens ... ( might be overkill ... but ... )
Alain
Re: If endif loop with 'OR'
That's a good point. What does happen first, the comparison or the subtraction, in the first snippet. In the second you'd be sure the subtraction was done prior to the comparison. I'm sure I'll get schooled here but with code there is often no such thing as overkilled overkill.
Re: If endif loop with 'OR'
Hi,
In my case the subtraction happens first.
C.
Re: If endif loop with 'OR'
At least for C languages this, according to wikipedia, is the order of operations. I tried to find something more specific to PBP or the BASIC stamp but couldn't. This topic may be getting off topic but I thought it interesting to know at least a pseudo answer.
1 () [] -> . :: Function call, scope, array/member access
2 ! ~ - + * & sizeof type cast ++ -- (most) unary operators, sizeof and type casts (right to left)
3 * / % MOD Multiplication, division, modulo
4 + - Addition and subtraction
5 << >> Bitwise shift left and right
6 < <= > >= Comparisons: less-than, ...
7 == != Comparisons: equal and not equal
8 & Bitwise AND
9 ^ Bitwise exclusive OR (XOR)
10 | Bitwise inclusive (normal) OR
11 && Logical AND
12 || Logical OR
13 ? : Conditional expression (ternary)
14 = += -= *= /= %= &= |= ^= <<= >>= Assignment operators (right to left)
15 , Comma operator
Re: If endif loop with 'OR'
Precedence from the pbp3 manual
Quote:
The following table lists the operators in default hierarchal order. (Parentheses will
override.) Operators with the same precedence level (on the same line in the table
below) will be evaluated in the order (left to right) that they are encountered in the
written expression.
Highest Precedence
( ) (anything enclosed in parentheses)
- (unary)
! or NOT, ABS, COS, DCD, DIV32, NCD, SIN, SQR
<<, >>, ATN, DIG, HYP, MAX, MIN, REV
*, /, **, */, //
+, - (in math), ~
= or ==, <> or !=, <, <=, >, >=
&, |, ^, &/, |/, ^/
AND, OR, XOR, ANDNOT, ORNOT, XORNOT
Lowest Precedence
camerart's problem is that he is using Oshonsoft's version of picbasic not pbppro
picbasic != pbppro
Re: If endif loop with 'OR'
Ah, what I posted should compile in C or PBP, and in both languages inner brackets should evaluate first, and in order toward outer brackets.
PBP
Code:
if (battery=charged) && (lightbulb != blown) then ‘ AND
bulb will light
endif
C
Code:
if (battery=charged) && (lightbulb != blown) { ‘ AND
bulb will light
}
Quote:
Originally Posted by
camerart
Hi Art,
As I've been monolingual with basic since the early 80s, your reply is another puzzle, but thanks. I'll stick to IF/THEN.
C.
Re: If endif loop with 'OR'
Quote:
Ah, what I posted should compile in C or PBP, and in both languages inner brackets should evaluate first, and in order toward outer brackets.
C
if (battery=charged) && (lightbulb != blown) { ‘ AND bulb will light }
not really in C (battery=charged) is not a comparison it's an assignment ,while the statement will compile in C the results will be incorrect
(battery==charged) is a comparison statement in C
Re: If endif loop with 'OR'