Need help ? to build the logic of the code

import java.util.*;

class seqInteger {
    public static void main(String args[]){
    
        Scanner sc = new Scanner(System.in);
        System.out.print(" Please Enter any integer: ");
        int no=sc.nextInt();
        do{
            System.out.print(no+" ");
            no++;
         
        }while(no>0);
       
        sc.close();     
         
    }
}

I got the out only entered no.
Could you explain ? why the do while loop exit.

I am expecting…

Input : -5
output: -5 -4 -3 -2 -1 0

The logic inside your while loop states to keep looping while the number is bigger than zero. If you entered -5 as your input, it will only loop once, since you wrote a do - while loop.

1 Like

Thanks very much TomerPacific