The use of while loop and do while loop in c

while loop and do while loop in c

The while loop and the do while loop are common loop structures in C. The difference is that the do while loop can execute statements before judgment, while the while loop judges first and then executes.

Implementation

Implementation of while loop:

#include<stdio.h>

int main() {
    
    
	 int index = 6;
	 while (index <= 5) {
    
    
		printf("%d\n", index);
		//index = index + 1;
		index++;        
	}
	return 0;
}

Output is empty

Implementation of do while loop:

#include<stdio.h>

int main() {
    
    
	 int index = 6;
	 do {
    
    
		printf("%d\n", index);
		//index = index + 1;
		index++;
	} while (index <= 5);
	
	return 0;
}

Output:
Insert image description here

Guess you like

Origin blog.csdn.net/balabala_333/article/details/131910219