Skip to content
Open
Show file tree
Hide file tree
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
55 changes: 55 additions & 0 deletions examples/stage0/solutions/src/loops.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2026 FRCSoftware
*
* SPDX-License-Identifier: BSD-3-Clause
*/

class Drivetrain {
/**
* Dummy function that spins drivetrain motors at the specified speed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Dummy function that spins drivetrain motors at the specified speed.
* Mock function to simulate running drivetrain motors at specified throttle

It's probably best to use throttle as the variable name

* @param speed
*/
public void setThrottle(double speed) {
System.out.println("Spinning drivetrain motors at speed: " + speed);
}
}
Drivetrain drivetrain = new Drivetrain();

void main() {

// First, create a new integer variable named `error`
// Below, create a while loop that compares if error is less than 5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Below, create a while loop that compares if error is less than 5
// Below, create a while loop that checks if `error` is less than 5

// if that is true, print "Robots should not quit", then increase `error` by one
// if error is no longer less than 5, print "but yours did"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// if error is no longer less than 5, print "but yours did"
// when `error` is no longer less than 5, print "but yours did"

Comment on lines +22 to +23

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is funny to us, but might be confusing and not very intuitive what the students should be trying to accomplish with this loop. What if we made a more realistic scenario like:

A robot gyro must be calibrated before using it. Calibrating is done by printing "Calibrating..." to the console 5 times. Using a while loop and an integer, calibrate the gyro, then print "Calibration successful"

int error = 0;
while (error < 5){
System.out.println("Robots should not quit");
error++;
}
System.out.println("but yours did");

// Create a for loop that has a new integer variable named `timer`
// that is set to 15. Check for when timer is greater than or equal to 0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// that is set to 15. Check for when timer is greater than or equal to 0,
// that is set to 15. Check for when `timer` is greater than or equal to 0,

// then decrease timer by one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// then decrease timer by one.
// then decrease `timer` by one.

// Inside the for loop, include a print statement that prints "time left: "
// and the variable `timer`
for (int timer = 15; timer >= 0; timer--){
System.out.println("time left: " + timer);
}

// First, create a for loop that has a new integer variable named
// `timer` that is set to 15. The for loop checks if `timer` is
// greater than or equal to 0 then it decreases timer by one

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// greater than or equal to 0 then it decreases timer by one
// greater than or equal to 0, then it decreases `timer` by one

// Inside the for loop, have an if statement that checks if timer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Inside the for loop, have an if statement that checks if timer
// Inside the for loop, have an if statement that checks if `timer`

// is less than or equal to 0. If so, set the drivetrain speed to 0
// If the timer is less than or equal to 15, set the speed to one

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// If the timer is less than or equal to 15, set the speed to one
// If the `timer` is less than or equal to 15, set the speed to one

for (int timer = 15; timer >= 0; timer--){
if (timer <= 0 ){
drivetrain.setThrottle(0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this extra line the result of spotless/prettify or is it accidental?

} else if (timer <= 15 ){
drivetrain.setThrottle(1);
}
}

}
48 changes: 48 additions & 0 deletions examples/stage0/templates/src/loops.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2026 FRCSoftware
*
* SPDX-License-Identifier: BSD-3-Clause
*/

class Drivetrain {
/**
* Dummy function that spins drivetrain motors at the specified speed.
* @param speed
*/
public void setThrottle(double speed) {
System.out.println("Spinning drivetrain motors at speed: " + speed);
}
}
Drivetrain drivetrain = new Drivetrain();

void main() {

// First, create a new integer variable named `error`
// Below, create a while loop that compares if error is less than 5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Below, create a while loop that compares if error is less than 5
// Below, create a while loop that checks if `error` is less than 5

// if that is true, print "Robots should not quit", then increase `error` by one
// if error is no longer less than 5, print "but yours did"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// if error is no longer less than 5, print "but yours did"
// when `error` is no longer less than 5, print "but yours did"







// Create a for loop that has a new integer variable named `timer`
// that is set to 15. Check for when timer is greater than or equal to 0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// that is set to 15. Check for when timer is greater than or equal to 0,
// that is set to 15. Check for when `timer` is greater than or equal to 0,

// then decrease timer by one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// then decrease timer by one.
// then decrease `timer` by one.

// Inside the for loop, include a print statement that prints "time left "
// and the variable `timer`





// First, create a for loop that has a new integer variable named
// `timer` that is set to 15. The for loop checks if `timer` is
// greater than or equal to 0 then it decreases timer by one

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// greater than or equal to 0 then it decreases timer by one
// greater than or equal to 0, then it decreases `timer` by one

// Inside the for loop, have an if statement that checks if timer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Inside the for loop, have an if statement that checks if timer
// Inside the for loop, have an if statement that checks if `timer`

// is less than or equal to 0. If so, set the drivetrain speed to 0
// If the timer is less than or equal to 15, set the speed to one

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// If the timer is less than or equal to 15, set the speed to one
// If the `timer` is less than or equal to 15, set the speed to one



}
Loading