List Iteration with a Condition
The list articleWordCounts contains the word count for each of several articles. Which of the following code segments correctly calculates the number of articles with more than 500 words and stores the result in the variable count?
A
for (wordCount > 500 in articleWordCounts) { count++; }
B
foreach wordCount in articleWordCounts { if (wordCount > 500) count++; }
C
for each (wordCount in articleWordCounts) { if (wordCount > 500) count++; }
D
for each wordCount > 500 in articleWordCounts { count++; }
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | mahmoudjibrin08 | 1 | 2 | 0m 34s | 56 |
| #2 | gtsak31 | 1 | 1 | 1m 12s | 28 |
| #3 | 20231725 | 0 | 1 | 0m 00s | -10 |
| #4 | jasonvikathompson | 1 | 2 | 2m 02s | -32 |
| #5 | afeldman0610 | 0 | 1 | 0m 43s | -53 |
| #6 | tianbo.shen | 0 | 1 | 0m 55s | -65 |
| #7 | soniahalepota2005 | 1 | 2 | 2m 48s | -78 |
| #8 | rpatton | 1 | 2 | 4m 45s | -195 |
| #9 | bhavneet.singhal | 1 | 4 | 4m 47s | -217 |
Items per page:
10
1 – 9 of 9
