Docsity

Java Loops and Random Numbers: Understanding continue, break, exit, and assert, Slides of Java Programming

Toggle sidebar
bg1
More Loops and
Random Numbers
99 bottles of beer on the wall, 99 bottles of beer!
Take one down, pass it around, 98 bottles of beer on the wall!
98 bottles of beer on the wall, 98 bottles of beer!
Take one down, pass it around, 97 bottles of beer on the wall!
97 bottles of beer on the wall, 97 bottles of beer!
Take one down, pass it around, 96 bottles of beer on the wall!
...
(for loop?)
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Java Loops and Random Numbers: Understanding continue, break, exit, and assert and more Slides Java Programming in PDF only on Docsity!

More Loops and

Random Numbers

99 bottles of beer on the wall, 99 bottles of beer! Take one down, pass it around, 98 bottles of beer on the wall! 98 bottles of beer on the wall, 98 bottles of beer! Take one down, pass it around, 97 bottles of beer on the wall! 97 bottles of beer on the wall, 97 bottles of beer! Take one down, pass it around, 96 bottles of beer on the wall! ... (for loop?)

Highlights

  • continue, break and exit
  • assert
    • random numbers

break

break will exit the current loop (See: Break.java) doSkip true

System.exit(0)

System.exit(0) will completely stop your program (See: Exit.java)

Infinite loops

(See: CountingSheep.java)

Debugging

When your program is not working, it is often helpful to add println commands to find out what is going on Normally displaying the value of your variables will help you solve the issue (See: ReverseString.java)

assert

The assert command can also be helpful when debugging This can ensure certain boolean expressions are indeed true. (See: Assert.java) (Note: need to add -enableassertions )