Changes between Version 2 and Version 3 of ControlSystems/SoftwareTeam/Training/GettingStarted/Conditionals
- Timestamp:
- Nov 4, 2019, 3:28:03 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/Conditionals
v2 v3 27 27 * Change the values stored in the variable rangeInInches to 25 and observe the flow of the program. 28 28 29 === Extra Credit === 29 === Understanding the program 30 In the example above, we 31 1. Create a variable named rangeInInches. Notice how the name of the variable conveys information about what type of information can be held in it including the units; this is a very good programming practice and will make your programs more readable. 32 1. Store a value (10) in the variable rangeInInches.[[BR]] 33 In a robot program, we might get the value from a distance measurement sensor. 34 1. Compare the value to 20 35 1. If the value is less than 20, we display the message ''stop motors so we don't crash!''.[[BR]] 36 In a robot program, we would actually stop the motors 37 1. If the value is not less than 20, we display the message ''full speed ahead!'' 38 39 30 40 Java allows you to have multiple conditionals using the syntax: 31 41 {{{ … … 41 51 You can have as many ''else if'' clauses as you wish. 42 52 43 * Try adding an ''else if'' clause to the sample program.44 45 53 Some things to note: 46 54 * The conditions are always placed within parentheses … … 48 56 * The conditions are evaluated in order and the '''first''' condition that matches is executed, the rest are skipped 49 57 * The ''else if'' and ''else'' clauses are optional 58 59 === Extra Credit === 60 * Try adding an ''else if'' clause to the sample program: 61 * Read more about Java conditionals [https://www.w3schools.com/java/java_conditions.asp here] 62