From 139fa202c9380740df625245f47128b24b21e5e6 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 7 Feb 2020 20:54:07 -0500 Subject: Googletest export Refactor function GetNextPrime so that the loop precondition is checked before loop instead of during every loop run. Also by removing the loop condition, it shows that the only exit from the loop is the return statement. PiperOrigin-RevId: 293932783 --- googletest/samples/prime_tables.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/googletest/samples/prime_tables.h b/googletest/samples/prime_tables.h index 72539bf..34002f3 100644 --- a/googletest/samples/prime_tables.h +++ b/googletest/samples/prime_tables.h @@ -66,11 +66,11 @@ class OnTheFlyPrimeTable : public PrimeTable { } int GetNextPrime(int p) const override { - for (int n = p + 1; n > 0; n++) { + if (p < 0) return -1; + + for (int n = p + 1;; n++) { if (IsPrime(n)) return n; } - - return -1; } }; -- cgit v0.12