[Coco] C VS Basic Coco
James Jones
jejones3141 at gmail.com
Tue Feb 13 13:04:43 EST 2018
BASIC09 has a FOR loop; I'd recommend it in this case for a couple of
reasons:
- It shows what you want the initial value of a to be--are you sure that
you can count on the value of variables that aren't explicitly assigned to
or read?
- It's shorter--in this case it is better suited to what you want to do
than the very general LOOP...ENDLOOP. The loop exit condition is implied by
the bounds given, so you don't have to write it out.
That would give
DIM a: INTEGER
FOR a := 10 TO 19
PRINT a
NEXT a
Explicitly saying a is an integer is possible in this case. It's worth
doing where possible because integer operations are a lot faster than, and
save memory over, floating point, which BASIC09 makes the default for
compatibility with other BASICs.
On Tue, Feb 13, 2018 at 10:08 AM, Taylor, Phillip L CIV <
Phillip.L.Taylor at uscg.mil> wrote:
>
>
> I the reason I like basic is because it's much easer to learn and read the
> source code. The example below 8 lines of basic code 6 lines of code vs C
> is 8 lines of code.
>
> Basic is more simple less code:
>
> Loop
> A = A +1
> Print A
> Exitif A < 20
> EndExit
> Endloop
>
>
>
>
> C Code is harder to learn:
>
> #include <stdio.h>
>
> int main () {
>
> int a;
>
> /* for loop execution */
> for( a = 10; a < 20; a = a + 1 ){
> printf("value of a: %d\n", a);
> }
>
> return 0;
> }
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>
More information about the Coco
mailing list