-
-
Notifications
You must be signed in to change notification settings - Fork 731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created Ternary operator file under Control Structure #684
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,71 @@ | ||||||||||||
--- | ||||||||||||
title: ternary | ||||||||||||
categories: [ "Structure" ] | ||||||||||||
subCategories: [ "Control Structure" ] | ||||||||||||
--- | ||||||||||||
|
||||||||||||
|
||||||||||||
|
||||||||||||
|
||||||||||||
|
||||||||||||
= ?: Ternary Operator | ||||||||||||
|
||||||||||||
|
||||||||||||
// OVERVIEW SECTION STARTS | ||||||||||||
[#overview] | ||||||||||||
-- | ||||||||||||
|
||||||||||||
[float] | ||||||||||||
=== Description | ||||||||||||
It takes three arguments rather than the typical one or two that most operators use. The first argument is a comparison argument, the second is the result upon a true comparison, and the third is the result upon a false comparison. It is an alternative to shorten an if-else block. It can help increase the readability and reduce the number of lines in your code. | ||||||||||||
[%hardbreaks] | ||||||||||||
|
||||||||||||
|
||||||||||||
[float] | ||||||||||||
=== Syntax | ||||||||||||
`expression_1 ? expression_2 : expression_3; // if expression_1 evaluates to true then expression_2 is evaluated else expression_3` | ||||||||||||
|
||||||||||||
|
||||||||||||
[float] | ||||||||||||
=== Parameters | ||||||||||||
`expression`. An expression is any legal combination of symbols that represents a value. | ||||||||||||
|
||||||||||||
-- | ||||||||||||
// OVERVIEW SECTION ENDS | ||||||||||||
|
||||||||||||
|
||||||||||||
|
||||||||||||
// HOW TO USE SECTION STARTS | ||||||||||||
[#howtouse] | ||||||||||||
-- | ||||||||||||
|
||||||||||||
[float] | ||||||||||||
=== Example Code | ||||||||||||
|
||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think this location is more appropriate for the description, rather than the previous location as a comment at the end of the code block. |
||||||||||||
[source,arduino] | ||||||||||||
---- | ||||||||||||
int x = 10, y = 20, z; // declared and defined three variables x, y and z | ||||||||||||
z = (x < y) ? x : y; | ||||||||||||
Comment on lines
+47
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Beginners are likely to be unfamiliar with the ability to declare multiple variables in one statement. This is not documented in the Arduino Language Reference and they won't understand that the language contains all the capabilities of C++ and that the missing documentation for those capabilities can be found in any C++ reference, since this fact is not documented (#623). In this case, using a separate statement for each declaration is actually just as good because the function of the code is now so clear that an explanatory comment is unnecessary. |
||||||||||||
// the statement checks the conditional expression and assigns z the value of x, the expression x<y is true | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This accompanies my suggestion above to move the description out of the code block. |
||||||||||||
---- | ||||||||||||
[%hardbreaks] | ||||||||||||
|
||||||||||||
|
||||||||||||
-- | ||||||||||||
// HOW TO USE SECTION ENDS | ||||||||||||
|
||||||||||||
|
||||||||||||
|
||||||||||||
|
||||||||||||
// SEE ALSO SECTION | ||||||||||||
[#see_also] | ||||||||||||
-- | ||||||||||||
|
||||||||||||
[float] | ||||||||||||
=== See also | ||||||||||||
|
||||||||||||
[role="language"] | ||||||||||||
|
||||||||||||
|
||||||||||||
-- | ||||||||||||
// SEE ALSO SECTION ENDS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use standard format for parameter documentation:
reference-en/AsciiDoc_sample/Reference_Terms/AsciiDoc_Template-Single_Entity.adoc
Line 43 in ac98490