So far we've made the computer print out a static message. Instead, lets make it do a bit of work - I've always had trouble with my seven times table and I'd like to check what 5 * 7 is.
So far we've made the computer print out a static message. Instead, lets make it do a bit of work - I've always had trouble with my seven times table and I'd like to check what 5 * 7 is.
So far we've made the computer print out a static message. Instead, lets make it do a bit of work - I've always had trouble with my seven times table and I'd like to check what 5 * 7 is.
Actually, now that I think of it, I need to know 6 * 7 as well.
Actually, now that I think of it, I need to know 6 * 7 as well.
Actually, now that I think of it, I need to know 6 * 7 as well.
And 7*7.
And 7*7.
And 7*7.
There is one quantity here which is varying each time I try out the program. I could put it in a Java variable, which helps the program model the fact that I am looking for something times seven.
There is one quantity here which is varying each time I try out the program. I could put it in a Java variable, which helps the program model the fact that I am looking for something times seven.
There is one quantity here which is varying each time I try out the program. I could put it in a Java variable, which helps the program model the fact that I am looking for something times seven.
Let's call this variable n, because it is a little number.
Let's call this variable n, because it is a little number.
Let's call this variable n, because it is a little number.
We are using integer values, so we must declare this variable to be of type int
We are using integer values, so we must declare this variable to be of type int
We are using integer values, so we must declare this variable to be of type int
Before we can safely use n in an expression, we must put a value in it, or initialise it in Java terminology.
Before we can safely use n in an expression, we must put a value in it, or initialise it in Java terminology.
Before we can safely use n in an expression, we must put a value in it, or initialise it in Java terminology.
Let's make it print another calculation!
Let's make it print another calculation!
Let's make it print another calculation!
And another one!
And another one!
And another one!
And another
And another
And another
Again! Again!
Again! Again!
Again! Again!
Encore!
Encore!
Encore!
Each time round as well as printing the same expression, we are just incrementing the value stored in n. Let's make that obvious.
Each time round as well as printing the same expression, we are just incrementing the value stored in n. Let's make that obvious.
Each time round as well as printing the same expression, we are just incrementing the value stored in n. Let's make that obvious.
Each time round as well as printing the same expression, we are just incrementing the value stored in n. Let's make that obvious.
Each time round as well as printing the same expression, we are just incrementing the value stored in n. Let's make that obvious.
Each time round as well as printing the same expression, we are just incrementing the value stored in n. Let's make that obvious.
Each time round as well as printing the same expression, we are just incrementing the value stored in n. Let's make that obvious.
Each time round as well as printing the same expression, we are just incrementing the value stored in n. Let's make that obvious.
Each time round as well as printing the same expression, we are just incrementing the value stored in n. Let's make that obvious.
Each time round as well as printing the same expression, we are just incrementing the value stored in n. Let's make that obvious.
Each time round as well as printing the same expression, we are just incrementing the value stored in n. Let's make that obvious.
Notice how we are doing exactly the same thing in each line of the program. Instead of tediously writing the same line of code over and over again, we can use a loop.
We want to instruct the computer that the same thing must be done over and over again (that's called the loop body) for a particular set of values (that's the loop conditions).
The loop body contains the instructions that are the same each time round. The loop conditions are the instructions that tell the loop how to start, what changes to make each time the loop body is run, and how to check whether the loop has finished or not.
We'll dive in feet first and turn these statements into a loop; then we'll come back and explain the syntax! So this line will be the loop body...
We'll dive in feet first and turn these statements into a loop; then we'll come back and explain the syntax! So this line will be the loop body...
...and here's the starting condition...
...and here's the starting condition...
...we'll think about how to check whether the loop has finished a bit later...
...but here's the change that has to be made each time the body is run.
...but here's the change that has to be made each time the body is run.
Let's get rid of the repeated print instruction...
Let's get rid of the repeated print instruction...
Let's get rid of the repeated print instruction...
...and replace it with a proper loop body in curly braces.
...and replace it with a proper loop body in curly braces.
...and replace it with a proper loop body in curly braces.
This is going to be a for loop which puts the loop conditions in parentheses in front of the loop body.
This is going to be a for loop which puts the loop conditions in parentheses in front of the loop body.
This is going to be a for loop which puts the loop conditions in parentheses in front of the loop body.
This is going to be a for loop which puts the loop conditions in parentheses in front of the loop body.
This is going to be a for loop which puts the loop conditions in parentheses in front of the loop body.
This is going to be a for loop which puts the loop conditions in parentheses in front of the loop body.
This is going to be a for loop which puts the loop conditions in parentheses in front of the loop body.
To finish the loop off, we need to supply a loop continuation test. We know that we continue for as long as n<=12, so that's all we need to add.
To finish the loop off, we need to supply a loop continuation test. We know that we continue for as long as n<=12, so that's all we need to add.
To finish the loop off, we need to supply a loop continuation test. We know that we continue for as long as n<=12, so that's all we need to add.
Now we've got it, let's look at its anatomy. A for loop...
Now we've got it, let's look at its anatomy. A for loop...
...consists of a loop body...
...consists of a loop body...
...and loop conditions which govern the circumstances under which the loop body is executed...
...and loop conditions which govern the circumstances under which the loop body is executed...
... i.e. what happens when the loop starts...
... i.e. what happens when the loop starts...
... what circumstances must hold true for the loop body to continue to execute
... what circumstances must hold true for the loop body to continue to execute
...and what changes must happen between each time the loop body is executed.
...and what changes must happen between each time the loop body is executed.
We've pretty much finished except to say that it is very easy to improve this program by printing out the complete seven-times table.
We've pretty much finished except to say that it is very easy to improve this program by printing out the complete seven-times table.
We've pretty much finished except to say that it is very easy to improve this program by printing out the complete seven-times table.
We've pretty much finished except to say that it is very easy to improve this program by printing out the complete seven-times table.
We've pretty much finished except to say that it is very easy to improve this program by printing out the complete seven-times table.
We've pretty much finished except to say that it is very easy to improve this program by printing out the complete seven-times table.
We've pretty much finished except to say that it is very easy to improve this program by printing out the complete seven-times table.
Finished code.
public class HelloWorld{
public static void main(String[] arg){
System.out.println("Hello World");
}
}
public class HelloWorld{
public static void main(String[] arg){
System.out.println("Hello World");
}
}
public class HelloWorld{
public static void main(String[] arg){
System.out.println(5 * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
System.out.println(5 * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
System.out.println(5 * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
System.out.println(6 * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
System.out.println(6 * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
System.out.println(6 * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
System.out.println(7 * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
System.out.println(7 * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
System.out.println(7 * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
System.out.println(??? * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
System.out.println(??? * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
System.out.println(??? * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
*System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
*System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
* }
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n=8; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n=8; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n=8; System.out.println(n * 7);
* }
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n=8; System.out.println(n * 7);
n=9; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n=8; System.out.println(n * 7);
n=9; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n=8; System.out.println(n * 7);
n=9; System.out.println(n * 7);
* }
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n=8; System.out.println(n * 7);
n=9; System.out.println(n * 7);
n=10; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n=8; System.out.println(n * 7);
n=9; System.out.println(n * 7);
n=10; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n=8; System.out.println(n * 7);
n=9; System.out.println(n * 7);
n=10; System.out.println(n * 7);
* }
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n=8; System.out.println(n * 7);
n=9; System.out.println(n * 7);
n=10; System.out.println(n * 7);
n=11; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n=8; System.out.println(n * 7);
n=9; System.out.println(n * 7);
n=10; System.out.println(n * 7);
n=11; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n=8; System.out.println(n * 7);
n=9; System.out.println(n * 7);
n=10; System.out.println(n * 7);
n=11; System.out.println(n * 7);
* }
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n=8; System.out.println(n * 7);
n=9; System.out.println(n * 7);
n=10; System.out.println(n * 7);
n=11; System.out.println(n * 7);
n=12; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n=8; System.out.println(n * 7);
n=9; System.out.println(n * 7);
n=10; System.out.println(n * 7);
n=11; System.out.println(n * 7);
n=12; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n=8; System.out.println(n * 7);
n=9; System.out.println(n * 7);
n=10; System.out.println(n * 7);
n=11; System.out.println(n * 7);
n=12; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n=9; System.out.println(n * 7);
n=10; System.out.println(n * 7);
n=11; System.out.println(n * 7);
n=12; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n=9; System.out.println(n * 7);
n=10; System.out.println(n * 7);
n=11; System.out.println(n * 7);
n=12; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n=10; System.out.println(n * 7);
n=11; System.out.println(n * 7);
n=12; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n=10; System.out.println(n * 7);
n=11; System.out.println(n * 7);
n=12; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n=11; System.out.println(n * 7);
n=12; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n=11; System.out.println(n * 7);
n=12; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n=12; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n=12; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
n++; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7;
n++;
n++;
n++;
n++;
n++; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7;
n++;
n++;
n++;
n++;
n++; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7;
n++;
n++;
n++;
n++;
n++; System.out.println(n * 7);
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7;
n++;
n++;
n++;
n++;
n++; {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
n=7;
n++;
n++;
n++;
n++;
n++; {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
*n=7;
n++;
n++;
n++;
n++;
n++; {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7;
n++;
n++;
n++;
n++;
n++; {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7;*
n++;
n++;
n++;
n++;
n++; {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; <i>missing loop continuation test</i>;
n++;
n++;
n++;
n++;
n++; {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; <i>missing loop continuation test</i>;
n++;
n++;
n++;
n++;
n++; {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; <i>missing loop continuation test</i>; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; <i>missing loop continuation test</i>; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; <i>missing loop continuation test</i>; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=7; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
for(n=1; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
*for(n=1; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
System.out.println("The 7 Times Table");
for(n=1; n<=12; n++) {
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
System.out.println("The 7 Times Table");
for(n=1; n<=12; n++) {
*System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
System.out.println("The 7 Times Table");
for(n=1; n<=12; n++) {
System.out.print(n);
System.out.print(" * 7 = ");
System.out.println(n * 7);
}
}
}
public class HelloWorld{
public static void main(String[] arg){
int n;
System.out.println("The 7 Times Table");
for(n=1; n<=12; n++) {
System.out.print(n);
System.out.print(" * 7 = ");
System.out.println(n * 7);
}
}
}