1234
def findGreatestDivisor(n): for divisor in range(n-1,0,-1): if n%divisor == 0: return divisor
1234567
int findGreatestDivisor(int n) { for (int div = n-1 ; 0; div -= 1) { if ( n % div == 0) { return div; } } }
for (int div = n-1 ; 0; div -= 1)
for (int div = n-1 ; div > 0; div -= 1 )
int findGreatestDivisor(int n) { for (int div = n-1 ; div > 0; div -= 1) { if ( n % div == 0) { return div; } } }
12345678
int findGreatestDivisor(int n) { for (int div = n-1 ; div > 1; div -= 1) { if ( n % div == 0) { return div; } } return 1; }
12345678910
int findGreatestDivisor(int n) { if( n < 0 ) n = -n ; // if negative, make it positive for (int div = n-1 ; div > 0; div -= 1) { if ( n % div == 0 ) return div; } return 1 ; // if the loop never executed (if n == 0 or n == 1) }