Java for Beginners 5 : While Loop and Euclidean Algorithm

Опубликовано: 04 Июль 2026
на канале: shawnkoon
5,861
62

Hello guys! this shawn koon here, I hope you enjoyed this video..!
If you guys liked my videos, please subscribe for more future videos :) Thank you

Whats up guys, today we are going to learn about while loop in java. It's one of the most commonly used loop structure. So, first i went over the basic structure of the while loop with an condition and after that i used this one really good example that uses while loop. Which is the "Euclid GCD" or known as "Ecuclidean algorithm". what it does is, it finds the greatest common divisor with given two numbers. For example, 21 and 35 's GCD would be 7 because 7 is the largest number that can be divided into 21
and 35.

1. Loop Structure.
int count = 0;

while (count ( 10) (- condition
{
System.out.println("Oh noo");


// count = count + 1; (- increment
count++; (- increment
}

============================================================
2. Euclid GCD

int num1 = 21; Also known as
int num2 = 35; . 2 .
. 1 2 .
while (num2 ) 0) . 1 2 .
{ . 2 .
int rem = num 1 % num2; . 1 .
num1 = num2; ....................
num2 = rem;
}

System.out.println("The GCD is: " + num1);