0% found this document useful (0 votes)
15 views9 pages

Java Loop Control Statements Examples

The document contains a series of code snippets demonstrating various control flow structures in Java, including loops and conditional statements. Each snippet illustrates different behaviors such as breaking out of loops, continuing to the next iteration, and printing specific values based on conditions. The examples cover for-loops, while-loops, and do-while loops with different conditions and outputs.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views9 pages

Java Loop Control Statements Examples

The document contains a series of code snippets demonstrating various control flow structures in Java, including loops and conditional statements. Each snippet illustrates different behaviors such as breaking out of loops, continuing to the next iteration, and printing specific values based on conditions. The examples cover for-loops, while-loops, and do-while loops with different conditions and outputs.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

int i;

for(i = 1; i <= 5; i++)

if(i % 2 == 0)

[Link](i + " ");

2. int i = 5;

while(i >= 1)

[Link](i);

i--;

3. int i = 1;

do

[Link](i + " ");

i += 2;

while(i <= 7);

4. for(int i = 1; i <= 10; i++)

if(i == 6)

break;

[Link](i + " ");

5. for(int i = 1; i <= 5; i++)


{

if(i == 3)

continue;

[Link](i + " ");

6. int i = 0;

while(i < 5)

i++;

if(i == 2)

continue;

[Link](i + " ");

7. int i = 1;

do

if(i == 4)

break;

[Link](i + " ");

i++;

while(i <= 5);

8. for(int i = 1; i <= 3; i++)

for(int j = 1; j <= i; j++)

{
[Link](j);

[Link]();

9. for(int i = 1; i <= 4; i++)

if(i % 2 == 0)

[Link]("E ");

else

[Link]("O ");

10. for(int i = 1; i <= 7; i++)

if(i == 3)

continue;

if(i == 6)

break;

[Link](i + " ");

11. int i = 1;

while(i++ <= 5)

[Link](i + " ");

12. for(int i = 1; i <= 5; i++)

{
if(i++ > 3)

break;

[Link](i + " ");

13. for(int i = 1; i <= 5; i++)

if(i % 2 == 1)

continue;

[Link](i);

14. int i = 10;

do

[Link](i + " ");

i++;

while(i <= 5);

15. int i = 1;

while(i <= 3)

[Link](i + " ");

i++;

16. for(int i = 1; i <= 3; i++)

for(int j = 1; j <= 3; j++)

if(j == 2)
break;

[Link](i + "" + j + " ");

17. for(int i = 1; i <= 3; i++)

for(int j = 1; j <= 3; j++)

if(j == 2)

continue;

[Link](i + "" + j + " ");

18. int i;

for(i = 1; i++ <= 5;)

[Link](i + " ");

19. int x = 5;

if(x++ > 5)

[Link](x);

[Link](x);

20. int i = 1;

while(i <= 5)

[Link](i++ + " ");


}

21. for(int i = 5; i-- > 0;)

[Link](i + " ");

22. int i = 0;

do

i++;

if(i == 3)

continue;

[Link](i + " ");

while(i < 5);

23. for(int i = 1; i <= 5; i++)

if(i == 2 || i == 4)

continue;

[Link](i + " ");

24. for(int i = 1; i <= 3; i++)

for(int j = 1; j <= 3; j++)

if(i == j)

break;
[Link](i + "" + j + " ");

25. int i = 5;

while(i < 5)

[Link](i);

26. int i = 0;

while(i < 5)

if(i == 2)

continue;

[Link](i + " ");

i++;

27. int i;

for(i = 1; i <= 5; i++);

[Link](i);

28. int i = 1;

while(i <= 3)

int j = 1;

while(j <= i)

[Link](j);
j++;

[Link]();

i++;

29. for(int i = 1; i <= 5; i++)

if(i == 4)

break;

[Link](i + " ");

30. for(int i = 1; i <= 3; i++)

if(i == 2)

continue;

[Link](i);

31. int i = 1;

while(i <= 5)

if(i % 2 == 0)

[Link](i);

i++;

32. for(int i = 1; i <= 5; i++)

{
[Link](i++ + " ");

33. int i = 0;

do

[Link](i + " ");

i++;

while(i < 0);

34. int i = 1;

while(i++ <= 3)

[Link](i + " ");

35. for(int i = 1; i <= 5; i++)

if(i == 3)

continue;

if(i == 5)

break;

[Link](i + " ");

You might also like