Re: [PIC] Learning C

David C Brown <[email protected]>
Newsgroups gmane.comp.hardware.microcontrollers.pic
Message-ID <CAFo_nNoCWh-eQwT8oC4A1M_evmRp=joHB4osMrsd56Hu=ahyrQ@mail.gmail.com>
It ight be more compact but the if...else formulation is much clearer.  So
clear in fact that someone not trained in programming could understand
what it means
__________________________________________
David C Brown
43 Bings Road
Whaley Bridge
High Peak                           Phone: 01663 733236
Derbyshire                eMail: [email protected]
SK23 7ND          web: www.bings-knowle.co.uk/dcb
<http://www.jb.man.ac.uk/~dcb>



*Sent from my etch-a-sketch*


On Thu, 14 Nov 2024 at 16:17, Spehro Pefhany <[email protected]> wrote:

> At 03:56 AM 2024-11-14, you wrote:
> >Ans 404 to you :-)
> >
> >Onew of the problems I have with trying to understand code examples in C
> is
> >that so many of them are incomprehensibly dense.
> >What would be five or six lines in Pascal or Basic is a single line in C.
> >I appreciate that that is down to the programmer not the language but it
> is
> >off putting
> >i have to remind my self of the old adage:  You can write Pascal in any
> >language
>
> I do like the ternary operator '?' in C (and in some other languages)
> which reduces several lines to one and is still very readable, maybe more
> so.
>
> variable = condition ? value_if_true : value_if_false
>
> instead of
>
> if (a > b) {
>      result = x;
> }
> else {
>      result = y;
> }
>
>
> just write
>
> result = a > b ? x : y;
>
> Best regards, Spehro Pefhany
> --
> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
> View/change your membership options at
> https://mailman.mit.edu/mailman/listinfo/piclist
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.