<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/94155>94155</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format] feature request: prevent indentation of some nested for loops
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
martinlicht
</td>
</tr>
</table>
<pre>
My code base contains loops such as
```
for (int i = 0; i < dim_x; i++)
for (int j = 0; j < dim_y; j++)
for (int k = 0; k < dim_z; k++)
{
table[i][j] = 0
}
```
Though opinions may vary, this style is not particularly exotic and I personally find it more readable and easier to debug than, say,
```
for (int i = 0; i < dim_x; i++)
{
for (int j = 0; j < dim_y; j++)
{
for (int k = 0; k < dim_z; k++)
{
table[i][j] = 0
}
}
}
```
Currently, clang-format does not support any option that would support the first style.
Generalizing from this example, the for loop style applies if only the inner-most loop contains a non-loop statement. My suggested compact option to achieve would be something like:
> If a for loop contains only another for loop (and no other statements), then put both loops on the same indentation level and do not use brackets.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVMGOo0gM_ZrKxUoERZgkBw6dzmY1h7ntfWXAQHUXZbbKZJv5-hUFk0zPzEqt1UoIsMrP9exnG0MwrSMqVH5W-WWDo3Tsix69GGdN1cmm5HoqvkxQcU1QYiCo2AkaF8AyDwHCWHWAAVRyUcnT-v6UrE80G_ag9NE4AQMqu0CisnP8fYba9H--RVPpc3xOP4FeHqCXO2iK5r-DXh-g1zvoazR_AKnDefkBABAsLan8bFR-Ufn5ReWXNdDqe_llisv7j47HtgMejDPsAvQ4wQ39pPQzSGcCBJksgQngWGCYy1yNFr2dgN5YTAXoavgMA_nADq2doDGuBiPQsyfwhPXML7oRBkMehKGmcmxBOnTzRQHn-_4_OeAXVfpP4szAd1F-iPRxxb6Bf4r2AQXhLuES4fIRYZ9H78mJjUpWFl27bdj3KFAzLWqGcRjYC6CbgAcx7GZFBP7m0db3U-kIGuODLK2wezc2v5Mjj9Z8Na6FxnO_NA29YT9YWpqIYsXm0VubCYfBGgpgGmBnp-hinCO_7TnI4nkfWQTHbruiUagnJzv4MkEY25aCUA0V9wNWcs-BAavO0I3WTEqCwD1JN5O05pVU9vSu2bLf4HMD-OB5vz3yQ8fSkX8cK32c29kxLAd3YmHWe0nawTAKlCzdunVidQkC9nO2NTnBSNfSjWwcj5qjLGMgKD1WryRhtzDc1EVWn7ITbqhID-kh03t9SjZdUZaYHJNjlSYHndVNmlRUn5J8v6_yI-r9cWMKneh98inRaZKlWbJLG2qwaQ4p0uGE1UntE-rR2J21t37Hvt2YEEYqTvs0zzcWS7IhLlutv-8ipfW8fn0xw7bl2Aa1T6wJEh6BxIiNi_odML9AQyhjXA5_jRREZU8weLrRPN7fVYabqBu4ReZv5Q-b0duiExnCLKS-Kn1tjXRjuau4V_o6E1g_28HzC1Wi9DWmFZS-LpndCv1PAAAA__9Pleig">