How to use for, switch and while in Java

Hi guys! In this tutorial I will explain to you how you can use for and while loops with Java. Also, I will explain to you how you can use switch and case with Java.

If you want use for statement with java, you can do it in this way:

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

{

System.out.println(i);

}

This code will display numbers from 0 to 10;

If I will use if(i == 4) continue; it will display 3 and 5 without 4.

To use while, you can write this code:

int i = 0;

while(i < 10)

{

System.out.println(i);

i++;

}

This code will display numbers from 0 to 10;

To use switch and case:

int i = 0;

switch (i)

{

case 1:

System.out.println(1);

break;

case 2:

System.out.println(2);

break;

default;

System.out.println(0);

break;

}

In the video bellow you can see how it works:









Leave a Comment