Skip to content

remove redundant "else" test in temperature example #451

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

Merged
merged 3 commits into from
Jun 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 81 additions & 82 deletions Language/Structure/Control Structure/else.adoc
Original file line number Diff line number Diff line change
@@ -1,82 +1,81 @@
---
title: else
categories: [ "Structure" ]
subCategories: [ "Control Structure" ]
---





= if...else


// OVERVIEW SECTION STARTS
[#overview]
--

[float]
=== Description
The `if...else` allows greater control over the flow of code than the basic link:../if[if] statement, by allowing multiple tests to be grouped together. An `else` clause (if at all exists) will be executed if the condition in the `if` statement results in `false`. The `else` can proceed another `if` test, so that multiple, mutually exclusive tests can be run at the same time.
[%hardbreaks]

Each test will proceed to the next one until a true test is encountered. When a true test is found, its associated block of code is run, and the program then skips to the line following the entire if/else construction. If no test proves to be true, the default `else` block is executed, if one is present, and sets the default behavior.
[%hardbreaks]

Note that an `else if` block may be used with or without a terminating `else` block and vice versa. An unlimited number of such `else if` branches is allowed.

[float]
=== Syntax
[source,arduino]
----
if (condition1) {
// do Thing A
}
else if (condition2) {
// do Thing B
}
else {
// do Thing C
}
----

--
// OVERVIEW SECTION ENDS



// HOW TO USE SECTION STARTS
[#howtouse]
--
[float]
=== Example Code
Below is an extract from a code for temperature sensor system
[source,arduino]
----
if (temperature >= 70) {
//Danger! Shut down the system
}
else if (temperature >= 60 && temperature < 70) {
//Warning! User attention required
}
else {
//Safe! Continue usual tasks...
}
----

--
// HOW TO USE SECTION ENDS



// SEE ALSO SECTION BEGINS
[#see_also]
--

[float]
=== See also

[role="language"]

--
// SEE ALSO SECTION ENDS
---
title: else
categories: [ "Structure" ]
subCategories: [ "Control Structure" ]
---

= if...else


// OVERVIEW SECTION STARTS
[#overview]
--

[float]
=== Description
The `if...else` allows greater control over the flow of code than the basic link:../if[if] statement, by allowing multiple tests to be grouped together. An `else` clause (if at all exists) will be executed if the condition in the `if` statement results in `false`. The `else` can proceed another `if` test, so that multiple, mutually exclusive tests can be run at the same time.
[%hardbreaks]

Each test will proceed to the next one until a true test is encountered. When a true test is found, its associated block of code is run, and the program then skips to the line following the entire if/else construction. If no test proves to be true, the default `else` block is executed, if one is present, and sets the default behavior.
[%hardbreaks]

Note that an `else if` block may be used with or without a terminating `else` block and vice versa. An unlimited number of such `else if` branches is allowed.

[float]
=== Syntax
[source,arduino]
----
if (condition1) {
// do Thing A
}
else if (condition2) {
// do Thing B
}
else {
// do Thing C
}
----

--
// OVERVIEW SECTION ENDS



// HOW TO USE SECTION STARTS
[#howtouse]
--
[float]
=== Example Code
Below is an extract from a code for temperature sensor system
[source,arduino]
----
if (temperature >= 70)
{
// Danger! Shut down the system
}
else if (temperature >= 60) // 60 <= temperature < 70
{
// Warning! User attention required
}
else // temperature < 60
{
// Safe! Continue usual tasks...
}
----

--
// HOW TO USE SECTION ENDS



// SEE ALSO SECTION BEGINS
[#see_also]
--

[float]
=== See also

[role="language"]

--
// SEE ALSO SECTION ENDS