The main difference between while and for loop is that we directly write some condition in while loop unlike for loop. In for loop, we first initialize some variable and then we increment it for a number of times. In while loop, we already have a variable and we just check the condition for it. while loop stops only when a condition becomes false.
Download: Click here to see the output of this program in your browser. Right-click and select Save Link as to download the file.