Chapter 12 Flashcards
What is a while statement and how does it work?
A while statement has a condition and based off of its condition will perform its statements over and over until the statement does not match the input for the condition. It acts as a loop until it does not match the input
What is another name for a while statement?
Another name for a while statement is a while loop
What is the stuff inside the curly braces in a while statement and what does it do?
The stuff inside the cooley braces repeats itself until it matches the input of the while statements conditions
What is it called every time the while statement loops?
It is called an iteration of the loop
What is a while statement similar to?
It is similar to an if statement as an executes what is in the curly braces if it matches the input but it loops it over and over again and that’s what’s the difference between an if statement and a while statement.
What elements can be used in both and if statement and a while statement within the curly braces?
You can write out statements to create a block statement which is more than one statement within the curly braces
what is an infinite loop?
it’s a continuing of the running of code that won’t stop producing text in the console view.
how do you stop a program dead in it’s tracks so that it doesn’t continue to run?
there is a small rectangular red square at the top of Eclipse’s Console view. as you hover your mouse above it, the tooltip says Terminate
in which cases is an infinite loop suitable?
code with an infinite loop is beneficial in air traffic control, the monitoring of a heart lung machine etc.
how do you create a perfect tab indentation in a call to print?
using “\t” creates a tab of indentation
what is a tab using “\t” or “\n” for bringing the cursor to a new tab called?
these are called escape sequences
how else can you bring the cursor to a newline without using System.out.println in your code?
you can use System.out.print(“ \n “)
what are the 3 steps in order, when creating loops that contain a random number for input and what is the correct first step to take and why?
first you need to initialize; set up intial values if needed
2nd; test condition; check if the random number meets the stopping condition
3rd; random input; Generate a new random number each time the loop runs.
what is priming the loop?
means setting up a condition so that the loop can run correctly from the start.
how many steps is there when priming a loop without a random number for the input? and what is the correct order?
Initialize (Prime the Loop): Get the first input before the loop starts.
Test Condition: Check if number is valid for continuing the loop.
Process (Print): Do something with the input (like print it).
Input (Update): Update the variable at the end of each iteration.