0% found this document useful (0 votes)
21 views15 pages

Java For Loops Explained

The document explains basic for loops in Java, highlighting their similarity to Karel. It provides a general structure of a for loop and includes multiple examples demonstrating how the loop iterates through values. The examples illustrate that a for loop with a condition of 'i < 3' will execute three times, outputting the values 0, 1, and 2.

Uploaded by

Hi e
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views15 pages

Java For Loops Explained

The document explains basic for loops in Java, highlighting their similarity to Karel. It provides a general structure of a for loop and includes multiple examples demonstrating how the loop iterates through values. The examples illustrate that a for loop with a condition of 'i < 3' will execute three times, outputting the values 0, 1, and 2.

Uploaded by

Hi e
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

AP Computer Science

Basic For Loops


For loops in Java are the
same as in Karel!
For Loops

for(int i = 0; i < COUNT; i++)


{
// code to execute count times
}
Example For Loop
for(int i = 0; i < 3; i++)
{
[Link](i);
}
i

0
Example For Loop
for(int i = 0; i < 3; i++)
{
[Link](i);
}
i

0
Example For Loop
for(int i = 0; i < 3; i++)
{
[Link](i);
}
i
0
0
Example For Loop
for(int i = 0; i < 3; i++)
{
[Link](i);
}
i
0
1
Example For Loop
for(int i = 0; i < 3; i++)
{
[Link](i);
}
i
0
1
Example For Loop
for(int i = 0; i < 3; i++)
{
[Link](i);
}
i
0
1
1
Example For Loop
for(int i = 0; i < 3; i++)
{
[Link](i);
}
i
0
1
2
Example For Loop
for(int i = 0; i < 3; i++)
{
[Link](i);
}
i
0
1
2
Example For Loop
for(int i = 0; i < 3; i++)
{
[Link](i);
}
i
0
1
2
2
Example For Loop
for(int i = 0; i < 3; i++)
{
[Link](i);
}
i
0
1
2
3
Example For Loop
for(int i = 0; i < 3; i++)
{ False
[Link](i);
}
i
0
1
2
3
Example For Loop
for(int i = 0; i < 3; i++)
{
[Link](i);
}
i
0 This is why when we go from

3
0 to less than 3 we go 3
1 times, we do 0, 1, and 2.
2

You might also like