Changes between Version 2 and Version 3 of ControlSystems/SoftwareTeam/Training/GettingStarted/Conditionals


Ignore:
Timestamp:
Nov 4, 2019, 3:28:03 PM (6 years ago)
Author:
David Albert
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/Training/GettingStarted/Conditionals

    v2 v3  
    2727* Change the values stored in the variable rangeInInches to 25 and observe the flow of the program.
    2828
    29 === Extra Credit ===
     29=== Understanding the program
     30In the example above, we
     311. 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.
     321. Store a value (10) in the variable rangeInInches.[[BR]]
     33   In a robot program, we might get the value from a distance measurement sensor.
     341. 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
    3040Java allows you to have multiple conditionals using the syntax:
    3141{{{
     
    4151You can have as many ''else if'' clauses as you wish.
    4252
    43 * Try adding an ''else if'' clause to the sample program.
    44 
    4553Some things to note:
    4654* The conditions are always placed within parentheses
     
    4856* The conditions are evaluated in order and the '''first''' condition that matches is executed, the rest are skipped
    4957* 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