From a0a1c40e02474393f45cc60dcc87ee9d1cc2436b Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Mon, 30 Sep 2024 13:04:23 -0500 Subject: [PATCH 1/2] Mention empty curlies Fixes #191 --- syntax.Rmd | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/syntax.Rmd b/syntax.Rmd index 5bc88cd..325570a 100755 --- a/syntax.Rmd +++ b/syntax.Rmd @@ -290,6 +290,8 @@ hierarchy easy to see: * `}` should be the first character on the line. +It is occassionally useful to have an empty curly braces block, in which case it should be written `{}`. + ```{r, eval = FALSE} # Good if (y < 0 && debug) { @@ -320,6 +322,8 @@ tryCatch( } ) +while (waiting_for_something()) {} + # Bad if (y < 0 && debug) { message("Y is negative") @@ -333,6 +337,10 @@ if (y == 0) message("x is negative or zero") } } else { y ^ x } + +while (waiting_for_something()) { + +} ``` ### If statements From 99340b2bbd29b4aaed17e0bfe59135f61784056c Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Mon, 30 Sep 2024 16:51:20 -0500 Subject: [PATCH 2/2] Add another negative example --- syntax.Rmd | 1 + 1 file changed, 1 insertion(+) diff --git a/syntax.Rmd b/syntax.Rmd index 325570a..f080fee 100755 --- a/syntax.Rmd +++ b/syntax.Rmd @@ -338,6 +338,7 @@ if (y == 0) } } else { y ^ x } +while (waiting_for_something()) { } while (waiting_for_something()) { }