From 87f320e1ade400e2cddc322d99a868ee7c0cf7c6 Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Wed, 17 Dec 2008 15:03:23 +0100
Subject: [PATCH] mention foreach (...)

---
 doc/coding-style.qdoc | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/doc/coding-style.qdoc b/doc/coding-style.qdoc
index 3e209157455..c2e886c85b3 100644
--- a/doc/coding-style.qdoc
+++ b/doc/coding-style.qdoc
@@ -108,6 +108,34 @@ in C++.
 \endcode
 
 
+\o Using Qt's foreach is ok in non-time critical code when using a QTL 
+   container. It is a nice way to keep line noise down and to give the
+   loop variable a proper name:
+
+\code
+        foreach (QWidget *widget, container)
+            doSomething(widget);
+
+        -VS-
+
+	Container::iterator end = container.end();
+	for (Container::iterator it = container.begin(); it != end; ++it)
+            doSomething(*it);
+\endcode
+   
+    If the loop variable can be made const, do so. This can prevent 
+    unnecessary detaching of shared data in some cases. So:
+
+\code
+        foreach (const QString &name, someListOfNames)
+            doSomething(name);
+        
+        - NOT -
+
+        foreach (QString name, someListOfNames)
+            doSomething(name);
+\endcode
+
 
 \section1 Formatting
 
-- 
GitLab