DEV Community

Arshad Ali
Arshad Ali

Posted on

JAVA- While Loop

    import java.util.Scanner;
    public class Main {

        public static void main(String[] args) {

        //while loop = executes a block of code as long as a it's condition remains true

        Scanner scanner = new Scanner(System.in);
        String  name = "";

        while(name.isBlank()) {
            System.out.println("Enter your name: ");
            name = scanner.nextLine();
        }

        System.out.println("Hello "+name);

    }

}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)