0 items
- Description
PRG 420 Wk 3 Discussion – Loop Syntax
Post a total of 3 substantive responses over 2 separate days for full participation. This includes your initial post and 2 replies to other students.
Due Thursday
Respond to the following in a minimum of 175 words:
Research and discuss the following:
- Is the following code syntactically correct? How did you determine your answer? If the following code is notsyntactically correct, what is missing? If it is syntactically correct, what is the expected result?
for ( ; ; ) {
System.out.println(“In the body of the loop”);
}
- Many programmers use variables named i, j, or kto increment a loop counter, as shown below. However, variables can be named anything a programmer wants to name them, as long as they follow Java™’s syntactical rules for variable names. What are the benefits and drawbacks of using variable names such as i to increment or decrement loop counters vs. other variable names, such as counter or myCounter or hour?
for (int i = 1; i <= 24; i++) { // using i as counter
if (i < 12) { // morning hours
System.out.println(i + ” a.m.”);
}
else if (i == 12) { // noon is a special case
System.out.println(i + ” p.m.”);
}
else // afternoon hours {
System.out.println(i-12 + ” p.m.”);
}
}
Due Monday
Reply to at least 2 of your classmates. Be constructive and professional in your responses.