diff options
| author | Cliff Click <cliffc@acm.org> | 2024-11-11 09:55:48 -0800 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2024-11-23 09:03:20 -0800 |
| commit | 688d2230b93b03f2d4505346ef3b89b0f4c46445 (patch) | |
| tree | 14a0fc88425a2f86a6f0a00f3c52334142d7d04c /chapter17/README.md | |
| parent | c523a94308747083a08cc8e698d5f02c043c6127 (diff) | |
| download | Simple-688d2230b93b03f2d4505346ef3b89b0f4c46445.tar.gz Simple-688d2230b93b03f2d4505346ef3b89b0f4c46445.zip | |
Allow C-style for loops
Diffstat (limited to 'chapter17/README.md')
| -rw-r--r-- | chapter17/README.md | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/chapter17/README.md b/chapter17/README.md index 95cc397e..b9733873 100644 --- a/chapter17/README.md +++ b/chapter17/README.md @@ -108,21 +108,39 @@ Allow `pred ? e_true : e_false`. Also allow `pred ? e_true`, where the false re is the zero type version of the true result. +## For Loops +Allow C/C++ style `for` loops: + +`for( init; test; next ) body` + +```cpp +int sum=0; +for( int i=0; i<arg; i++ ) + sum = sum + i; +return sum; +``` + +Any of `init`, `test` and `next` can be empty. +`init` allows for declaration of a new variable, with scope limited to the `for` expression. + +```cpp +int sum=0; +for( int i=0; i<arg; i++ ) + sum = sum + i; +return sum; +``` -C++-style for-loop for-interator -trinary switch - # Chapter 18: Functions Some thinking on function syntax: |
