Changes between Version 22 and Version 23 of ControlSystems/SoftwareTeam/Training/GettingStarted/IntroJava


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

--

Legend:

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

    v22 v23  
    1 == Loops
    2 It's also important for a program to be able to do things repeatedly; for example, the robot must read its sensors repeatedly and react only when certain conditions are met.  Consider (and try running) the following program:
    3 {{{
    4 public class LoopExample {
    5     public static void main(String args[]) {
    6         int counter; 
    7 
    8         counter = 1;
    9         while (counter <= 10) {
    10             System.out.println(counter);
    11             counter = counter + 1;
    12         }
    13     }
    14 }
    15 }}}
    16 * Save this program as !LoopExample.java
    17 * Run the program in the debugger with a breakpoint set at the line while (counter <= 10)
    18 * Step through the program a line at a time, observing the program output, variables, and flow of execution
    19 * There are three types of [https://www.geeksforgeeks.org/loops-in-java/ loops in Java] including while, for, and do loops.  Read about them and try a few!
    20 
    211== !Functions/Methods
    222All modern programming languages allow you to extend the language by creating new command words.  In Java, a new word is called a function.  Functions are like machines that have an input and an output; you put something(s) into the function execute the function and the function does something that might include providing an output.  Every Java function has 4 primary characteristics: