Follow us on Instagram: https://www.instagram.com/siyatechtal... 😊
-------------------------------------------------------------------------------------------------------------------------Imagine you're filling a water tank with a bucket. The tank has a capacity of 100 liters, and each bucket holds 10 liters of water. You need to keep filling the tank with buckets of water until the tank is full. After each bucket, you check if the tank is full. If it's not full, you keep going. Once it's full, you stop.
Here’s how this can be represented with a while loop in code:
int tankCapacity = 100; // The total capacity of the tank
int currentWaterLevel = 0; // The current amount of water in the tank
int bucketSize = 10; // The size of each bucket
while (currentWaterLevel less than tankCapacity) { // As long as the tank isn't full
System.out.println("Filling the tank with one bucket...");
currentWaterLevel += bucketSize; // Add water to the tank
System.out.println("Current water level: " + currentWaterLevel + " liters");
}
System.out.println("The tank is now full with " + currentWaterLevel + " liters of water.");
In this example:
The condition (currentWaterLevel less than tankCapacity) ensures that you keep adding water as long as the tank isn’t full.
After each bucket is added, the water level increases.
Once the water level reaches or exceeds the capacity, the loop stops, and the tank is full.
-------------------------------------------------------------------------------------------------------------------------
Copyright Disclaimer under Section 52 of the Copyright Act, 1957 (India):
This video is made for educational, informational, and entertainment purposes only. The content is transformative in nature, and its use is considered fair use under Indian copyright law. No copyright infringement is intended, and all rights belong to their respective owners. The purpose of this video is to educate, inform, and entertain, and it is not intended to harm or exploit any individual or entity. If you have any concerns or objections, please contact us at [email protected]