git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH JGIT] simplify loop with if and do while

From
Yann Simon <yann.simon.fr@gmail.com>
Date
Jan 31, 2009, 14:25 UTC
Message-ID
<1233411909.8213.0.camel@localhost>
replace if(condition) { do { } while (condition) } by while (condition)
{ }
Signed-off-by: Yann Simon <yann.simon.fr@gmail.com>
---
 .../src/org/spearce/jgit/lib/Repository.java       |   18
+++++++-----------
 1 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
index 038a869..b6efac1 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -247,11 +247,9 @@ public File toFile(final AnyObjectId objectId) {
 	public boolean hasObject(final AnyObjectId objectId) {
 		final PackFile[] packs = packs();
 		int k = packs.length;
-		if (k > 0) {
-			do {
-				if (packs[--k].hasObject(objectId))
-					return true;
-			} while (k > 0);
+		while (k > 0) {
+			if (packs[--k].hasObject(objectId))
+				return true;
 		}
 		return toFile(objectId).isFile();
 	}
@@ -288,12 +286,10 @@ public ObjectLoader openObject(final WindowCursor
curs, final AnyObjectId id)
 			throws IOException {
 		final PackFile[] packs = packs();
 		int k = packs.length;
-		if (k > 0) {
-			do {
-				final ObjectLoader ol = packs[--k].get(curs, id);
-				if (ol != null)
-					return ol;
-			} while (k > 0);
+		while (k > 0) {
+			final ObjectLoader ol = packs[--k].get(curs, id);
+			if (ol != null)
+				return ol;
 		}
 		try {
 			return new UnpackedObjectLoader(this, id);
-- 
1.6.0.6
Message 1 of 1 in “simplify loop with if and do while”
  1. simplify loop with if and do whileYann Simon, Jan 31, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.