Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 19:31 24 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : ELSEIF statements

Author Message
larny
Guru

Joined: 31/10/2011
Location: Australia
Posts: 346
Posted: 07:41am 28 Nov 2011
Copy link to clipboard 
Print this post

I have been trying to use the ELSEIF statement.

Here are 2 of several possibilities that I've tried without success. Please advise.

This one gives the error message:-

"Line 20 expected closing bracket"

I don't know what this means. There no opening bracket. ??

10 FOR A = 3 TO 7
15 PRINT A
20 IF A < 5 THEN PRINT "A < 5" ELSEIF A = 5 THEN PRINT "A = 5" ELSE PRINT "A > 5"
25 ENDIF
30 NEXT
40 END


This programme works but does not execute the ELSEIF line.

10 FOR A = 3 TO 7
15 PRINT A
20 IF A < 5 THEN PRINT "A < 5"
25 ELSEIF A = 5 THEN PRINT "A = 5" ELSE PRINT "A > 5"
27 ENDIF
30 NEXT
40 END


The output is:-
3
A < 5
4
A < 5
--------------correct so far.
5 (A = 5)
6 (A > 5)
7 (A > 5)

The contents inside the brackets indicate what the output should be.

What am I missing?

Any assistance will be appreciated.

Len
Edited by larny 2011-11-29
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6097
Posted: 07:53am 28 Nov 2011
Copy link to clipboard 
Print this post

Try this:

100 FOR A = 3 TO 7
110 PRINT A
120 IF A < 5 THEN
130 PRINT "A < 5"
140 ELSEIF A = 5 THEN
150 PRINT "A = 5"
160 ELSE
170 PRINT "A > 5"
180 ENDIF
190 NEXT
200 END


You were mixing up one line if's with multiline.

Jim
VK7JH
MMedit   MMBasic Help
 
larny
Guru

Joined: 31/10/2011
Location: Australia
Posts: 346
Posted: 12:11am 29 Nov 2011
Copy link to clipboard 
Print this post

Thanks Jim,
That worked beautifully.

Len
 
graynomad

Senior Member

Joined: 21/07/2010
Location: Australia
Posts: 122
Posted: 01:23am 29 Nov 2011
Copy link to clipboard 
Print this post

OK I'm going to cop some flak for this, but here goes anyway :)

What's with the line numbers, non-indented code, and all caps? Is that enforced by MMbasic (I assume that's what language it is) or are we on a 70s retro trip?

______
Rob


Rob Gray, AKA the Graynomad, www.robgray.com
 
aargee
Senior Member

Joined: 21/08/2008
Location: Australia
Posts: 255
Posted: 03:37am 29 Nov 2011
Copy link to clipboard 
Print this post

  graynomad said   OK I'm going to cop some flak for this, but here goes anyway :)

What's with the line numbers, non-indented code, and all caps? Is that enforced by MMbasic (I assume that's what language it is) or are we on a 70s retro trip?

______
Rob



MM Basic is as close to the old 70-80s style BASICs (sorry, but BASIC is an acronym...) as you can get.

You cannot maintain indented code. All code will be hard up against the left, with line numbers and in capital letters as per Geoff's intention (have a read of the Maximite BASIC page here).

Yes, the Maximite can be thought of as a form of 70s retro trip in it's pure BASIC sense. But the Maximite is much more than that!

- Rob.
Edited by aargee 2011-11-30
For crying out loud, all I wanted to do was flash this blasted LED.
 
crackerjack

Senior Member

Joined: 11/07/2011
Location: Australia
Posts: 164
Posted: 03:40am 29 Nov 2011
Copy link to clipboard 
Print this post

Only Line Numbers are required by MMBasic (for now, we all hope). CAPS and the world's worst practice of non-indented code is a matter of personal preference for some ex-COBOL hipsters among the forum crew. The Maximite does MAJUSCULATE keywords, but not variable names and is not case-sensitive. In other words: None of MMBasic is a capitonym.
 
aargee
Senior Member

Joined: 21/08/2008
Location: Australia
Posts: 255
Posted: 03:53am 29 Nov 2011
Copy link to clipboard 
Print this post

I seem to manage the line numbers OK and the non-indented coding and I've never touched COBOL! It's all GW-BASIC to me.

I'm not really sure what your Maximite is doing in the second sentence, but it sounds like that episode of The Big Bang Theory involving the robot arm. Hospital pictures would be priceless, especially showing the Maximite.

"In other words..." they ain't! (words that is).

8-)

- Rob.
For crying out loud, all I wanted to do was flash this blasted LED.
 
graynomad

Senior Member

Joined: 21/07/2010
Location: Australia
Posts: 122
Posted: 03:57am 29 Nov 2011
Copy link to clipboard 
Print this post

Jeez crackerjack your post sent me scurrying for the dictionary

I did some COBOL programming in a previous life, that was my first thought when I saw the above code.

The Maximite looks like a great board and obviously more than just a 70s retro trip. It has an ICSP header so I guess you can fire up the C compiler but I assume that's not really the intended market.

So the BASIC interpreter just needs improving a little, maybe dragged into the 90s at least.

______
Rob Edited by graynomad 2011-11-30
Rob Gray, AKA the Graynomad, www.robgray.com
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6097
Posted: 04:26am 29 Nov 2011
Copy link to clipboard 
Print this post

  graynomad said  
So the BASIC interpreter just needs improving a little, maybe dragged into the 90s at least.

______
Rob


If you do like the Maximite but hate line numbers you could try MM Edit.
I wrote it because I also prefer to code without line numbers.
MM Edit doesn't do indenting (yet) and any indents will be stripped as it converts the code to line numbers. That saves space and time for the interpreter.

One of these days, I will add indenting built in help and coloured keywords etc but for now, I just want to make life a bit easier for the beginners.

http://www.c-com.com.au/MMedit.htm

Jim
VK7JH
MMedit   MMBasic Help
 
graynomad

Senior Member

Joined: 21/07/2010
Location: Australia
Posts: 122
Posted: 04:37am 29 Nov 2011
Copy link to clipboard 
Print this post

That looks good.

I gather Geoff wrote the interpreter in 8 days, pretty impressive, but he might be over it by now so maybe that's the way to do it, an editor that is also a pre processor.

Is the MMbasic source open?

______
Rob
Rob Gray, AKA the Graynomad, www.robgray.com
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024