Can we use two while loops for this code

I completely understood what Garima mam did in Pattern 13 but can we not use two while loops instead of if else …

I tried this but it did not even read the second while loop.
why ?

Scanner scn = new Scanner(System.in);
int n = scn.nextInt();

	int nst = 1;
	int row = 1;
	
	while(row <= n) {
		
		int cst = 1;
		while (cst <= nst) {
			System.out.print("*");
			cst++;
	}
		System.out.println();
		nst++;
		row++;
	}
	

	while(row <= n-1) {
		
		int cst2 = n-1;
		while(cst2 >= nst) {
			cst2--;
		}
		
		System.out.println();
		nst++;
		row++;
	} 

I m sorry for posting such silly dbts but what can I do…

your nst and row need to be redefined as 1 if you want to include a second loop
here is your corrected code:

if this solves your doubt please mark it as resolved :slight_smile: